   (-lookup [idx val]
     (-lookup idx val nil))
   (-lookup [idx val not-found]
-    (let [compfn (.-compfn idx)
-          keyfn (.-keyfn idx)
-          arry (.-arry idx)
-          index (goog.array.binarySearch arry val #(compfn %1 (keyfn %2)))]
+    (let [index (goog.array.binarySearch arry val #(compfn %1 (keyfn %2)))]
       (if (>= index 0)
         (loop [end index]
           (if (= (compfn val (keyfn (aget arry end))) 0)

    (-lookup idx k not-found))

  ICounted
  (-count [idx] (.-length (obj/getValues (.-hashmap idx))))

  p/IIndex
  (key-fn [idx] (.-keyfn idx))
  (index! [idx obj]
    (let [key ((.-keyfn idx) obj)
          hashmap (.-hashmap idx)
          old (js-lookup hashmap key)]
      (js-assoc hashmap key (if old (js-merge old obj) obj))))
  (unindex! [idx obj]
    (let [key ((.-keyfn idx) obj)
          hashmap (.-hashmap idx)]
      (js-dissoc hashmap key obj))))

(defn root-index [keyfn]

  (-lookup [store val]
    (-lookup store val nil))
  (-lookup [store id not-found]
    (-lookup root id not-found))

  ICounted
  (-count [store] (-count root))

  IFn
  (-invoke [store k]
