 
 (defn- delay-balances?
   [entity-id]
-  true
   (get-in @ambient-settings [entity-id :delay-balances?]))
 
 (defn- before-save-item
   "Makes pre-save adjustments for a transaction item"
   [item]
-  (cond-> item
-    true (update-in [:action] name)
-    (and (string? (:memo item))
-         (empty? (:memo item))) (dissoc :memo)))
+  (let [updated (update-in item [:action] name)]
+    (if (and (string? (:memo item))
+             (empty? (:memo item)))
+      (dissoc updated :memo)
+      updated)))
 
 (defn polarize-item-amount
   [item account]


(defn- before-item-validation
  [item]
  (cond-> item
    true (update-in [:value] #(or % (:amount item)))
    true (assoc :balance (bigdec 0))
    true (update-in [:index] (fnil identity (Integer/MAX_VALUE)))
    (string? (:account-id item)) (update-in [:account-id] #(Integer. %))
    (nil? (:id item)) (dissoc :id)
    (and
      (string? (:id item))
      (empty? (:id item))) (dissoc :id)
    (and
      (string? (:id item))
      (not (empty? (:id item)))) (update-in [:id] #(UUID/fromString %))))

(def ^:private coercion-rules
  [(coercion/rule :uuid [:id])

(defn- create-transaction-and-adjust-balances
  [storage transaction]
  (let [created (link-lots storage (create-transaction* storage transaction))]
    (doall (->> (:items transaction)

                ; create database records
                (map #(assoc % :transaction-id (:id created)))
                (map #(create-transaction-item* storage %))

                ; process indexes and balances, update affected accounts
                (group-by :account-id)
                (map second)
                (map #(sort-by :index %))
                (map first)
                (map #(get-previous-item storage %))
                (map #(recalculate-account-items storage %))
                (map #(recalculate-account-items storage %))))
    (reload storage created)))

(defn create
