   is created"
   [storage-spec user entity-name input source-type]
   (with-transacted-storage [s storage-spec]
-    (let [entity (entities/find-or-create s user  entity-name)
-          context (atom {:storage s
+    (let [context (atom {:storage s
                          :accounts {}
-                         :entity-id (:id entity)})]
-      (read-source source-type input (->Callback (fn [account] (swap! context #(import-account % account)))
-                                                 (fn [transaction] (swap! context #(import-transaction % transaction))))))))
+                         :entity (entities/find-or-create s user entity-name)})
+          callback (->Callback (fn [account]
+                                 (swap! context #(import-account % account)))
+                               (fn [transaction]
+                                 (swap! context #(import-transaction % transaction))))]
+      (read-source source-type input callback))))

        parent-id (get-in context [:accounts original-parent-id])
        to-create (cond-> account
                    true
                    (assoc :entity-id (:entity-id context))

                    true
                    (dissoc :id)

                    parent-id
                    (assoc :parent-id parent-id))
        result (accounts/create (:storage context) to-create)]
    (when-not (:id result)
      (throw (ex-info (str
                        "Unable to create the account "
                        (validation/error-messages result))
                      {:result result})))
    (update-in context [:accounts] #(assoc % original-id (:id result)))))

(defn- resolve-account-references
  [context items]
  (map (fn [item]
         (update-in item [:account-id] #(-> context :accounts (get %))))
       items))

(defn- prepare-transaction
  [context transaction]
  (-> transaction
      (update-in [:items] #(resolve-account-references context %))
      (assoc :entity-id (-> context :entity :id))))

(defn- import-transaction
  [context transaction]
  (->> transaction
       (prepare-transaction context)
       (transactions/create (:storage context)))
  ; Update anything in the context?
  ; don't want to include all transactions,
  ; as that can be many
  context)

(defn import-data
  "Reads the contents from the specified input and saves
