     storage-spec
     {:id ids
      :transaction-date (vec (concat [:between] date-range))}))
-
-(defn recalculate-balances
-  "Recalculates balances for the specified account and all
-  related transaction items"
-  [storage-spec account-id]
-  (with-storage [s storage-spec]
-    (let [result (->> {:account-id account-id}
-                      (search-items storage-spec)
-                      (reduce calculate-item-index-and-balance {:index 0
-                                                                :balance 0M
-                                                                :storage s}))]
-      (when-not (::skip-account-update result)
-        (accounts/update storage-spec (-> (accounts/find-by-id s account-id)
-                                          (assoc :balance (:balance result))))))))
-
 
 (defmacro with-delayed-balancing
   [storage-spec entity-id & body]

     ~@body

     ; Recalculate balances for affected accounts
     (doseq [account-id# (get-in @ambient-settings [~entity-id :delayed-account-ids])]
       (recalculate-balances ~storage-spec account-id#))

     ; clean up the ambient settings as if we were never here
     (swap! ambient-settings dissoc ~entity-id)))

                       (remove #(= id (:id %)) items))]
    (when-let [last-balance (:last-balance result)]
      (accounts/update storage (assoc account :balance last-balance)))))

(defn- link-lots
  [storage transaction]
