     (let [new-children (assoc children index new-child)]
       [(->RootNode keys new-children)]))
   (insert [node index new-child1 median new-child2]
-    ;(println "root recieving split children")
-    (let [new-children (vec (concat (take index children)
-                                    [new-child1 new-child2]
-                                    (drop (inc index) children)))
-          ;;TODO find a better datastructure than vector
-          ;;use the vector with lg time split/merge
-          new-keys (vec (concat (take index keys)
-                                [median]
-                                (drop index keys)))]
-      ;(println "new keys:" new-keys)
-      (if (>= (count new-children) (* 2 b))
-        (let [split-med (nth new-keys (dec b))
-              left-index (->IndexNode (vec (take (dec b) new-keys))
-                                      (vec (take b new-children)))
-              right-index (->IndexNode (vec (drop b new-keys))
-                                       (vec (drop b new-children)))
-              median (nth new-keys (dec b))]
-          [left-index median right-index])
-        [(->RootNode new-keys
-                     new-children)])))
+    (handle-multi-insert ->RootNode node index new-child1 median new-child2))
   INodeLookup
   (lookup [root key]
     (scan-children-array keys key)))


(def b 3)

(defprotocol INodeLookup
  (lookup [node key] "Returns the child node which contains the given key"))

(defprotocol IKeyCompare
  (compare [key1 key2]))

(defprotocol IInsert
  (insert [node index new-child]
          [node index new-child1 median new-child2]
          "Returns one or 2 new nodes, if it had to split"
          ))

(extend-protocol IKeyCompare
  Object
  (compare [key1 key2] (clojure.core/compare key1 key2)))

(defprotocol IResolve
  "This is how we store the children. The indirection enables background
   fetch and decode of the resource."
  (resolve [this]))

(defn scan-children-array
  "This function takes an array of keys. There must be an odd # of elts in it.

    (let [new-children (assoc children index new-child)]
      [(->IndexNode keys new-children)]))
  (insert [node index new-child1 median new-child2]
    (handle-multi-insert ->IndexNode node index new-child1 median new-child2))
  INodeLookup
  (lookup [root key]
    (scan-children-array keys key)))
