 
            (== old-var new-var)
            ;; ACROSS: assumes prefixes all equal, keys not all equal, iterators sorted by ascending key, nothing at end
-           (let [iterators (aget var->iterators new-var)
-                 num-iterators (alength iterators)
-                 previous (mod (- current 1) num-iterators)
-                 max-key (.key-at (aget iterators previous) new-var)
-                 iterator (aget iterators current)
+           (let [var-iterators (aget var->iterators new-var)
+                 num-var-iterators (alength var-iterators)
+                 previous (mod (- current 1) num-var-iterators)
+                 max-key (.key-at (aget var-iterators previous) new-var)
+                 iterator (aget var-iterators current)
                  min-key (.key-at iterator new-var)
                  old-key (.inner-key iterator)]
              (debug :search max-key current seek-key)

  (end? [this]
        (.-end? iterator)))

(deftype Join [seek-key iterators var->iterators ^:mutable end?]
  Object
  (reset [this]
         (debug)

           (if (== old-var (- (alength var->iterators) 1))
             nil ;; done
             (let [new-var (+ old-var 1)
                   var-iterators (aget var->iterators new-var)
                   iterator->reset? (aget var->iterator->reset? new-var)]
               (debug :down old-var old-key seek-key)
               (dotimes [i (alength iterators)]
                 (debug :resets iterator->reset? :for new-var)
                 (when (true? (aget iterator->reset? i))
                   (debug :resetting i :to seek-key :at new-var)
                   (doto (aget iterators i) (.reset) (.seek seek-key)))) ;; TODO this could be implemented more efficiently
               (js/goog.array.sort var-iterators (fn [i0 i1] (compare (.key-at i0 new-var) (.key-at i1 new-var))))
               (if (== (.key-at (aget var-iterators 0) new-var) (.key-at (aget var-iterators (- (alength var-iterators) 1)) new-var))
                 (do
                   (aset seek-key new-var (.key-at (aget var-iterators 0) new-var))
                   (recur new-var (+ new-var 1) 0))
                 (recur new-var new-var 0))))))
  (next [this]
