          (aset marked-nodes ix (.-node itr))
          (aset marked-ixs ix (.-ix itr))))
      (.set-key magic)
-     (ainto (.-prev-seek magic) (.key magic))
+     (.make-min magic)
+     (when (identical? (.-end? magic) false)
+       (ainto (.-prev-seek magic) (.key magic)))
      magic)))
 
-(deftype JoinIterator [iterators ^:mutable cur-key ^:mutable next-key ^:mutable end? len tuple-len keys min-fill]
+(deftype JoinIterator [iterators ^:mutable cur-key ^:mutable next-key ^:mutable end? len tuple-len]
   Object
+  (make-min [this]
+            (.key this))
+
   (key [this]
-       cur-key)
-
-  (fillkeys [this]
-          (dotimes [x len]
-            (aset keys x (.key (aget iterators x)))))
-
-  (find-least [this]
-              (loop [ix 1
-                     col 0
-                     least (-> (aget keys 0)
-                               (aget 0))]
-                (if (>= ix len)
-                  (do
-                    (aset min-fill col least)
-                    (let [next (+ 1 col)]
-                      (if (< next tuple-len)
-                        (recur 0 next nil))))
-                  (let [cur (-> (aget keys ix)
-                                (aget col))]
-                    (recur (+ 1 ix) col (if (nilless-lt cur least)
-                                          cur
-                                          least))))))
+       (when (identical? end? false)
+         cur-key))
+
   (iters-next [this]
+              ;;try next on the last iterator
               (let [last (aget iterators (- len 1))]
                 (.next last)
                 (if-not (.-end? last)
-                  (reverse-fill! (.key last) min-fill)
+                  (ainto next-key (.key last))
+                  ;;otherwise walk up and get the min next value
                   (loop [ix (- len 2)]
                     (when (>= ix 0)
                       (let [cur (aget iterators ix)]
                         (.next cur)
                         (if (.-end? cur)
                           (recur (- ix 1))
-                          (reverse-fill-with! (.key cur) min-fill false))))))))
-  (find-greatest ^:boolean [this]
-                 ;(println keys)
-                 (loop [ix 1
-                        greatest (aget keys 0)
-                        found? true]
-                   (if (>= ix len)
-                     (if found?
-                       (let [greatest (fill! (.slice greatest 0) min-fill)]
-                        ;(println "    ***setting greatest: " greatest)
-                         (.iters-next this)
-                         (set! cur-key greatest)
-                         (ainto next-key min-fill)
-                         false)
+                          (ainto next-key (.make-min cur)))))))))
+
+  (seek-join [this]
+             ;;while we haven't found a match
+             (loop []
+               ;;seek each iterator
+               (loop [ix 0]
+                 (if (< ix len)
+                   (let [cur (aget iterators ix)
+                         cur-key (.key cur)]
+                     (.seek cur next-key)
+                     (if-not (.-end? cur)
                        (do
-                         (ainto next-key (reverse-fill! greatest min-fill))
-                         true))
-                     (let [comped (filled-key-compare greatest (aget keys ix) min-fill)
-                           comped-v (or comped greatest)]
-                      ;(println "g: " comped (and found? (not comped)) min-fill)
-                       (recur (+ 1 ix) comped-v (and found? (not comped))))))
-                )
-  (seek-all [this]
-            (loop [ix 0]
-              (if (< ix len)
-                (let [cur (aget iterators ix)
-                      cur-key (.key cur)]
-                 ;(println "searching for: " next-key)
-                 ;(println "    iterator " ix ": " cur-key)
-                  (.seek cur next-key)
-                 ;(println "    post iterator " ix ": " (.key cur))
-                  (if-not (.-iterator.end? cur)
-                    (do
-                      (reverse-fill! (.key cur) next-key)
-                      (recur (+ 1 ix)))
-                    (do
-                      (set! end? true)
-                      false)))
-                (do
-                 ;(println "    final search key: " okey)
-                  true)))
-            )
-  (init-join [this]
-             (.fillkeys this)
-             (.find-least this)
-             (when (identical? true (.find-greatest this))
-               (.seek-join this)))
-
-  (seek-join [this]
-             (loop [continue? true]
-               (when (identical? true continue?)
-                 (when (.seek-all this)
-                   (.fillkeys this)
-                   (.find-least this)
-                  ;(println "MIN FILL: " min-fill)
-                   (recur (.find-greatest this))
-                   )))
-             )
+                         (ainto next-key (.key cur))
+                         (recur (+ 1 ix)))
+                       (set! end? true)))))
+               (when (identical? end? false)
+                 (let [root-key (.key (aget iterators 0))
+                       last-key (.key (aget iterators (- len 1)))]
+                   ;;when the first and last keys are the same, we have a match
+                   (if (key= root-key last-key)
+                     (do
+                       (set! cur-key (.slice last-key 0))
+                       (.iters-next this))
+                     ;;otherwise recur
+                     (do
+                       (ainto next-key last-key)
+                       (recur))
+                     )))))
 
   (next [this]
-        (if end?
-          (set! cur-key nil)
-          (.seek-join this)
-          ))
+        (.seek-join this))
 
   (seek [this key]
         (when (key-lt cur-key key)
           (ainto next-key key)
-          (.next this))))
+          (.seek-join this))))
 
 (defn join-iterator [iterators]
   ;(println iterators)
   (let [len (alength iterators)
         results (array)
-        keys (array)
-        min-fill (array)
         root (aget iterators 0)
-        tuple-len (alength (.-map root))]
+        tuple-len (alength (.-map root))
+        next-key (array)]
     (if (or (== tuple-len 0)
             (not (.key root))
             (== 0 (alength (.key root))))
       (do
         (.next root)
         root)
-      (let [itr (JoinIterator. iterators (array) (array) false len tuple-len keys min-fill)]
-        (.init-join itr)
+      (let [itr (JoinIterator. iterators (array) next-key false len tuple-len)]
+        (dotimes [ix tuple-len]
+          (aset next-key ix false))
+        (.seek-join itr)
         itr
         ))))
 

(ns aurora.join
  (:require [aurora.btree :refer [tree iterator key-lt key-lte key-gt key-gte key-compare]])
  (:require-macros [aurora.macros :refer [typeof ainto]]))

(defn nilless-lt [a b]
  (if (== a nil)
    false
    (if (== b nil)
      true
      (or (and (identical? (typeof a) (typeof b))
               (< a b))
          (< (typeof a) (typeof b))))))

(defn gt [a b]
  (and (not (identical? a b))

                                    (magic-iterator tree #js [nil 0 nil nil 1 nil])
                                    (magic-iterator tree #js [nil nil 0 nil nil 1])]))
        ]
     (assert
      (= (map vec (time (all-join-results j)))
         (map vec #js [#js [0 0 0 0 0 0] #js [0 0 1 0 0 1] #js [0 1 0 0 1 0] #js [0 1 1 0 1 1] #js [1 0 0 1 0 0] #js [1 0 1 1 0 1] #js [1 1 0 1 1 0] #js [1 1 1 1 1 1]])))
  )

  (let [tree (tree 10)
