        (map second)
        (map #(sort-by :index %))
        (map first)
-       (map #(or (get-previous-item storage % (:transaction-date transaction))
+       (map #(or (get-previous-item storage %)
                  {:account-id (:account-id %)
                   :index -1
                   :balance 0}))))

      (delete-transaction-item storage id))
    (->> dereferenced-account-ids
         ; fake out an item because that's what get-previous-item expects
         (map #(hash-map :account-id % :id -1))
         (map #(or (get-previous-item storage % (:transaction-date transaction))
                   (assoc % :index -1 :balance (bigdec 0)))))))

(defn update

            s
            {:account-id (:account-id reference-item)
             :index [:>= (:index reference-item)]
             :transaction-date [:between (:transaction-date reference-item) (t/today)]} ; TODO: let the system look up the latest date
            {:sort [[:index :desc]]})
          (remove #(= (:id reference-item) (:id %)))
          (map after-item-read)))))
