                 (set! (.-lower right-node) (.-lower (aget children (+ median 1))))))
             (set! (.-keys right-node) (.slice keys (+ median 1)))
             (set! (.-vals right-node) (.slice vals (+ median 1)))
-            (.splice keys median (+ median 1))
-            (.splice vals median (+ median 1))
+            (.splice keys median (alength keys))
+            (.splice vals median (alength vals))
             (when-not (nil? children)
               (let [right-children (.slice children (+ median 1))]
                 (dotimes [ix (alength right-children)]

    (.assoc! tree :e 1)
    (.assoc! tree :f 1)
    (.assoc! tree :g 1)
    (.assoc! tree :h 1)
    (.assoc! tree :i 1)
    (.assoc! tree :j 1)
    (js/console.log tree)
    (.valid! tree)
    tree)

              (assert (= lower (aget keys 0)) (pr-str lower keys))
              (assert (= upper (aget keys (- (alength keys) 1)))))
            (do
              (assert (= lower (.-lower (aget children 0))) (pr-str lower (.-lower (aget children 0))))
              (assert (= upper (.-upper (aget children (- (alength children) 1)))) (pr-str upper (.-upper (aget children (- (alength children) 1)))))
              (assert (every? #(> (aget keys %) (.-upper (aget children %))) (range (count keys))))
              (assert (every? #(< (aget keys %) (.-lower (aget children (inc %)))) (range (count keys))))
              (dotimes [i (count children)] (.valid! (aget children i) min-keys max-keys))))))
