                           (recur min-key (mod (+ current 1) num-iterators)))))))))))
   (up [this old-var]
       ;; assumes prefixes and keys all equal, nothing at end
-      (prn :up old-var)
+      (prn :up old-var seek-key)
       (if (== old-var 0)
         (set! end? true)
         (let [new-var (- old-var 1)
               iterators (aget var->iterators new-var)
               iterator (aget iterators (- (alength iterators) 1))]
-          (when (< old-var (- (alength var->iterators) 1))
+          (when (< old-var (alength var->iterators))
             (aset seek-key old-var least))
           (.next iterator)
           (if (.end? iterator)

            (.search this new-var)))))
  (down [this old-var old-key]
        ;; assumes prefixes all equal, nothing at end
        (prn :down old-var old-key)
        (if (== old-var (- (alength var->iterators) 1))
          (aset seek-key old-var old-key) ;; done
          (let [new-var (+ old-var 1)


(deftype Join [seek-key iterators var->iterators ^:mutable end?]
  Object
  (reset [this]
         (prn)
         (prn :reset)
         (dotimes [i (alength iterators)]
           (.reset (aget iterators i)))
         (dotimes [i (alength seek-key)]
           (aset seek-key i least))
         (set! end? false)
         (.down this -1))
  (key [this]
       (when (false? end?)
         seek-key))
