               (loop []
                 (.-keys node)
                 key
-                (set! ix (.seek node key 0))
+                (set! ix (key-find (.-keys node) key))
                 (if (>= ix (alength (.-keys node)))
                   (if (nil? (.-children node))
                     (do

  (key [this]
       (.key (aget iterators 0)))
  (next [this]
        (when (false? end?)
          (let [max-iterator (aget iterators (- (alength iterators) 1))]
            (assert (false? (.-blocked? max-iterator)))
            (.next max-iterator)
            (.maintain this))))
  (seek [this key]
        (when (false? end?)
          (let [max-iterator (aget iterators (- (alength iterators) 1))]
            (assert (false? (.-blocked? max-iterator)))
            (.seek max-iterator key)
            (.maintain this)))))

(defn join [iterators num-vars iterator->var->nextable? iterator->var->present?]
  (let [seek-key (least-key num-vars)
        join-iterators (amake [i (alength iterators)]
                              (let [iterator (aget iterators i)
                                    var->present? (aget iterator->var->present? i)
                                    inner->outer (make-array (.-key-len iterator))
                                    outer->inner (make-array num-vars)
                                    var 0]
                                (dotimes [j num-vars]
                                  (when (true? (aget var->present? j))
                                    (aset inner->outer var j)
                                    (aset outer->inner j var)
                                    (set!! var (+ var 1))))
                                (JoinIterator. iterator outer->inner inner->outer (make-array (.-key-len iterator)) num-vars)))
        var->iterators (amake [j num-vars]
                              (let [var-iterators #js []]
                                ;; ensure non-nextable iterators are sorted first
                                (dotimes [i (alength iterators)]
                                  (when (and (true? (aget iterator->var->present? i j)) (false? (aget iterator->var->nextable? i j)))
                                    (apush var-iterators (aget join-iterators i))))
                                (dotimes [i (alength iterators)]
                                  (when (and (true? (aget iterator->var->present? i j)) (true? (aget iterator->var->nextable? i j)))
                                    (apush var-iterators (aget join-iterators i))))
                                var-iterators))
        var->iterator->push|pop? (amake [j num-vars]
                                     (amake [i (alength iterators)]
                                            (and (true? (aget iterator->var->present? i j))
                                                 (and (> j 0)
                                                      (false? (aget iterator->var->present? i (- j 1)))))))
        join (Join. seek-key join-iterators var->iterators var->iterator->push|pop? false)]
    (.reset join)
    join))


                  (aset outer-key (aget inner->outer inner-ix) (aget new-key inner-ix))))))
  (reset [this]
         (.reset iterator)
         (dotimes [i (alength outer-key)]
           (aset outer-key i least))
         (.maintain this))
  (key [this]
       outer-key)
