        :index -1
        :balance 0M}))
 
-(defn- process-item-balance-and-index
-  "Accepts a context containing
-    :previous-index   - The index of the previous item
-    :previous-balance - The balance of the previous item
-    :items            - The items processed so far
-    :storage          - Storage service
-
-  Returns the context with these updates
-    :previous-index   - updated to the index of the item just processed
-    :previous-balance - updated to the balance of the item just processed
-    :items            - appended with the item just processed
-    :storage          - Unchanged storage service"
-  [context item]
-  (let [next-index (+ 1 (:previous-index context))
-        account (accounts/find-by-id (:storage context) (:account-id item)) ; TODO: remove redundant calls to find the account
-        polarized-amount (accounts/polarize-amount item account)
-        next-balance (+ (:previous-balance context) polarized-amount)
-        updated-item (-> item
-                         (assoc :balance next-balance
-                                :index next-index))]
-    (-> context
-        (assoc :previous-index next-index
-               :previous-balance next-balance)
-        (update-in [:items] #(conj % updated-item)))))
-
-(defn- add-item-balance-and-index
-  "Updates the specified items, which belong to the specified account
-  with new balance and index values"
-  [storage [account-id items]]
-  (let [sorted-items (sort-by :index items)
-        previous-item (get-previous-item storage (first sorted-items))
-        previous-balance (or (get previous-item :balance)
-                             (bigdec 0))
-        previous-index (or (get previous-item :index) -1)]
-    (:items (reduce process-item-balance-and-index
-                    {:previous-index previous-index
-                     :previous-balance previous-balance
-                     :items []
-                     :storage storage}
-                    sorted-items))))
-
-(defn- subsequent-items
-  "Returns items in the specified account on or after the specified
-  transaction date, excluding the reference-item"
-  ([storage-spec reference-item]
-   (with-storage [s storage-spec]
-     (->> (select-transaction-items
-            s
-            {:account-id (:account-id reference-item)
-             :index [:>= (:index reference-item)]
-             :transaction-date [:>= (:transaction-date reference-item)]}
-            {:sort [[:index :asc]]})
-          (remove #(= (:id reference-item) (:id %)))
-          (map after-item-read)))))
-
 (defn find-item-by-id
   [storage-spec id transaction-date]
   (first (select-transaction-items storage-spec

      (if (validation/has-error? validated)
        validated
        (if (delay-balances? (:entity-id transaction))
            (create-transaction-without-balances s validated)
            (create-transaction-and-adjust-balances s validated))))))

(defn find-by-id
  "Returns the specified transaction"

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

(defn- link-lots
  [storage transaction]
