             #js [(Node. (cut new-keys     0 middle)
                         (cut new-pointers 0 middle))
                  (Node. (cut new-keys     middle)
-                        (cut new-pointers middle))])))))))
+                        (cut new-pointers middle))]))))))
+
+  (disj [this ^number key root? left right]
+    (let [idx (.lookup this key)]
+      (when-not (== -1 idx) ;; short-circuit, key not here
+        (let [child       (aget pointers idx)
+              left-child  (when (>= (dec idx) 0)                 (aget pointers (dec idx)))
+              right-child (when (< (inc idx) (alength pointers)) (aget pointers (inc idx)))
+              disjned     (.disj child key false left-child right-child)]
+          (when disjned     ;; short-circuit, key not here
+            (let [left-idx     (if left-child  (dec idx) idx)
+                  right-idx    (if right-child (+ 2 idx) (+ 1 idx))
+                  new-keys     (check-n-splice keys left-idx right-idx (.map disjned lim-key))
+                  new-pointers (splice pointers left-idx right-idx disjned)]
+              (rotate (Node. new-keys new-pointers) root? left right))))))))
 
 (deftype LeafNode [keys]
   Object
-
-  (append [this ^number path _ key]
+  (toString [_] (pr-str* (vec keys)))
+  
+  (len [_]
+    (alength keys))
+  
+  (merge [_ next]
+    (LeafNode. (.concat keys (.-keys next))))
+  
+  (merge-n-split [_ next]
+    (let [ks (merge-n-split keys (.-keys next))]
+      (return-array (LeafNode. (aget ks 0))
+                    (LeafNode. (aget ks 1)))))
+  
+  (lookup [_ key]
+    (let [idx (binary-search keys 0 (dec (alength keys)) key)]
+      (if (and (< idx (alength keys))
+                 (eq (aget keys idx) key))
+        idx
+        -1)))
+
+  (append [this ^number path _ key] ;; TODO figure out idx here
     (let [idx    (path-get path 0)
           keys-l (alength keys)]
       (cond

      (-write writer "\n")
      (dump (aget (.-pointers node) i) writer (str "  " offset)))))

;; (extend-type BTSet
;;   IPrintWithWriter
;;   (-pr-writer [o writer _]
;;     (dump (.-root o) writer "")))

(defn test-rand []
  (dotimes [i 100]
    (let [xss (repeatedly (rand-int 10000) #(rand-int 10000))
          xs  (distinct (sort xss))
          s   (into (btset) xss)]
      (when-not (= (vec s) xs)
        (throw (js/Error. xss)))))
  (println "Checked")
  :ok)



(deftype BTSet [root shift comparator]
  Object
;;   (toString [this]
;;     (pr-str* this))
  
  ICollection
  (-conj [set key] (btset-conj set key))

  ISet
  (-disjoin [set key]
    (btset-disj set key))
  
  ILookup 
  (-lookup [set k]
