 (defn magic-iterator [tree map]
    (let [nil-ixs (array)
          itr (iterator tree)
+         map-len (alength map)
+         rewindable (array)
          marked-nodes (js-obj 0 (.-node itr))
          marked-ixs (js-obj 0 0)
-         magic (MagicIterator. itr map nil-ixs (alength map) (array) (.slice (or (.key itr) (array)) 0) (array) marked-nodes marked-ixs false)]
-     (dotimes [ix (alength map)]
-       (when (identical? nil (aget map ix))
-         (.push nil-ixs ix)
-         (aset marked-nodes ix (.-node itr))
-         (aset marked-ixs ix (.-ix itr))))
+         magic (MagicIterator. itr map nil-ixs rewindable map-len (array) (.slice (or (.key itr) (array)) 0) (array) marked-nodes marked-ixs false)]
+     (loop [ix 0
+            potential (array)]
+       (when (< ix map-len)
+         (if (identical? nil (aget map ix))
+           (do
+             (.push nil-ixs ix)
+             (.push potential ix)
+             (aset marked-nodes ix (.-node itr))
+             (aset marked-ixs ix (.-ix itr))
+             (recur (+ ix 1) potential))
+           (do
+             (dotimes [x (alength potential)]
+               (.push rewindable (aget potential x)))
+             (recur (+ ix 1) (array))))))
      (.set-key magic)
      (.make-min magic)
      (when (identical? (.-end? magic) false)



  (iters-next [this]
              ;;try next on the last iterator
              (let [last (aget iterators (- len 1))]
                (.next last)
                (if-not (.-end? last)
                  (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))
                          (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 (.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]
        (.seek-join this))

          (set! (.-end? iterator) false)
          (set! end? false)
          (.set-key this)
          )

  (key [this]
