             w)]
     (when (nil? w)
       ;; Copy watches to an array for speed
-      (reduce-kv (fn [_ k f]
-                   (.push a k)
-                   (.push a f))
+      (reduce-kv #(.push a %2 %3)
                  nil (.-watches this)))
     (let [len (alength a)]
       (loop [i 0]

          wg watching]
      (set! watching der)
      (doseq [w der]
        (when (or (nil? wg)
                  (== -1 (.indexOf wg w)))
          (-add-watch w this handle-reaction-change)))
      (doseq [w wg]
        (when (or (nil? der)
                  (== -1 (.indexOf der w)))
          (-remove-watch w this))))
    nil)


                 (recur (inc i))
                 false))))))

(defn- ^boolean in-arr [a x]
  (not (or (nil? a)
           (== -1 (.indexOf a x)))))

(defn- in-context [obj f]
  (binding [*ratom-context* obj]
    (f)))

(defn- deref-capture [f r]
  (set! (.-captured r) nil)
  (when (dev?)
    (set! (.-ratomGeneration r)
          (set! generation (inc generation))))
  (let [res (in-context r f)
        c (.-captured r)]
    (set! (.-dirty? r) false)
    (when-not (arr-eq c (.-watching r))
      (._update-watching r c))
    res))

(defn- notify-deref-watcher! [derefable]
  (when-some [r *ratom-context*]
    (let [c (.-captured r)]
      (if (nil? c)
        (set! (.-captured r) (array derefable))
        (when-not (in-arr c derefable)
          (.push c derefable))))))

(defn- check-watches [old new]
