               (close! res)))
       res))
   (-assoc-in [this key-vec value]
-    (go (let [[fkey & rkey] key-vec
-              res (chan)
-              tx (.transaction db #js [store-name] "readwrite")
-              obj-store (.objectStore tx store-name)
-              req (.get obj-store (str fkey))]
-          (set! (.-onerror req)
-                (fn error-handler [e] (log e) (close! res) (throw e)))
-          (set! (.-onsuccess req)
-                (fn read-old [e]
-                  (let [old (when-let [r (.-result req)]
-                              (-> r .-edn_value read-string))
-                        up-req (.put obj-store
-                                     (clj->js {:key (str fkey)
-                                               :edn_value
-                                               (str (if-not (empty? rkey)
-                                                      (assoc-in old rkey value)
-                                                      value))}))]
-                    (set! (.-oncomplete up-req)
-                          (fn [e] (close! res))))))
-          (<! res))))
+    (let [[fkey & rkey] key-vec
+          res (chan)
+          tx (.transaction db #js [store-name] "readwrite")
+          obj-store (.objectStore tx store-name)
+          req (.get obj-store (str fkey))]
+      (set! (.-onerror req)
+            (partial error-handler (str "cannot get for assoc-in" fkey) res))
+      (set! (.-onsuccess req)
+            (fn read-old [e]
+              (let [old (when-let [r (.-result req)]
+                          (-> r .-edn_value read-string))
+                    up-req (.put obj-store
+                                 (clj->js {:key (str fkey)
+                                           :edn_value
+                                           (str (if-not (empty? rkey)
+                                                  (assoc-in old rkey value)
+                                                  value))}))]
+                (set! (.-onerror up-req)
+                      (partial error-handler (str "cannot put for assoc-in" fkey) res))
+                (set! (.-onsuccess up-req)
+                      (fn [e] (close! res))))))
+      res))
   (-update-in [this key-vec up-fn]
-    (go (let [[fkey & rkey] key-vec
-              res (chan)
-              tx (.transaction db #js [store-name] "readwrite")
-              obj-store (.objectStore tx store-name)
-              req (.get obj-store (str fkey))]
-          (set! (.-onerror req)
-                (fn error-handler [e] (log e) (close! res) (throw e)))
-          (set! (.-onsuccess req)
-                (fn read-old [e]
-                  (let [old (when-let [r (.-result req)]
-                              (-> r .-edn_value read-string))
-                        up-req (.put obj-store
-                                     (clj->js {:key (str fkey)
-                                               :edn_value
-                                               (str (if-not (empty? rkey)
-                                                      (update-in old rkey up-fn)
-                                                      (up-fn value)))}))]
-                    (set! (.-oncomplete up-req)
-                          (fn [e] (close! res))))))
-          (<! res)))))
+    (let [[fkey & rkey] key-vec
+          res (chan)
+          tx (.transaction db #js [store-name] "readwrite")
+          obj-store (.objectStore tx store-name)
+          req (.get obj-store (str fkey))]
+      (set! (.-onerror req)
+            (partial error-handler (str "cannot get for update-in" fkey) res))
+      (set! (.-onsuccess req)
+            (fn read-old [e]
+              (let [old (when-let [r (.-result req)]
+                          (-> r .-edn_value read-string))
+                    new (if-not (empty? rkey)
+                          (update-in old rkey up-fn)
+                          (up-fn value))
+                    up-req (.put obj-store
+                                 (clj->js {:key (str fkey)
+                                           :edn_value
+                                           (str new)}))]
+                (set! (.-onerror up-req)
+                      (partial error-handler (str "cannot put for update-in" fkey) res))
+                (set! (.-onsuccess up-req)
+                      (fn [e] (put! res [old new]) (close! res))))))
+      res)))
 
 
 (defn new-indexeddb-store [name]
   (let [res (chan)
         req (.open js/window.indexedDB name 1)]
     (set! (.-onerror req)
-          (fn error-handler [e]
-            (log (js->clj (.-target e)))
-            (close! res)
-            (throw e)))
+          (partial error-handler "ERROR opening DB:" res))
     (set! (.-onsuccess req)
           (fn success-handler [e]
             (log "db-opened:" (.-result req))
-            (put! res (IndexedDBKeyValueStore. (.-result req) "geschichte"))))
+            (put! res (IndexedDBKeyValueStore. (.-result req) name))))
     (set! (.-onupgradeneeded req)
           (fn upgrade-handler [e]
             (let [db (-> e .-target .-result)]


  (go (def my-db (<! (new-indexeddb-store "geschichte"))))

  (def my-kv (IndexedDBKeyValueStore. my-db "geschichte"))

  (go (println "get:" (<! (-get-in my-kv ["test"]))))

  (go (println (<! (-assoc-in my-kv ["test2"] {:a 1 :b 4.2}))))

  (go (println (<! (-assoc-in my-kv ["test" :a] 43))))

  (go (println (<! (-update-in my-kv ["test" :a] inc))))
  )

(defn start-server! [ip port]
  {throw "No server functionality in js yet. Node port welcome."})

(defn error-handler [topic res e]
  (.log js/console topic e) (close! res) (throw e))


(defrecord IndexedDBKeyValueStore [db store-name]
