               (.key iterator)))))
 
 (defn apply-to-elems [elems movements]
-  (let [elems (atom (cons [least nil] elems))]
+  (let [elems (atom elems)]
     (for [movement movements]
       (case (nth movement 0)
         :next (do
                 (swap! elems rest)
                 (first (first @elems)))
         :seek (do
+                (swap! elems rest)
                 (swap! elems (fn [elems] (drop-while #(lt-fun (nth % 0) (nth movement 1)) elems)))
                 (first (first @elems)))))))
 

                  nil)))
            (do
              (set! node (aget (.-children node) (+ ix 1)))
              (set! ix 0)))))
  (seek [this key]
        (loop [moved? false]
          (when (false? end?)
            (let [upper (.-upper node)]
              (if (lt upper key)
                (if (instance? Node (.-parent node))
                  (do
                    (set! ix (.-parent-ix node))
                    (set! node (.-parent node))
                    (recur true))
                  (do
                    (set! end? true)
                    nil))
                (loop [moved? moved?]
                  (set! ix (.seek node key ix))
                  (if (>= ix (alength (.-keys node)))
                    (do
                      (set! node (aget (.-children node) ix))
                      (set! ix 0)
                      (recur true))
                    (if (or (not moved?)
                            (== key (aget (.-keys node) ix))
                            (nil? (.-children node))
                            (let [lower (.-upper (aget (.-children node) ix))]
                              (lt lower key)))
                      nil
                      (do
                        (set! node (aget (.-children node) ix))
                        (set! ix 0)
                        (recur true)))))))))))

(defn iterator [tree]
  (loop [node (.-root tree)]
    (if (nil? (.-children node))
      (if (> (alength (.-keys node)) 0)
        (Iterator. (.-max-keys tree) node -1 false)
        (Iterator. (.-max-keys tree) node -1 true))
      (recur (aget (.-children node) 0)))))

(deftype Intersection [iterators end?]
  Object
  (key [this]
       (when (false? end?)

          (.next (aget iterators 0))
          (if (.-end? (aget iterators 0))
            (set! end? true)
            (.search this 1))))
  (seek [this key]
        (when (false? end?)
          (.seek (aget iterators 0) key)
          (if (.-end? (aget iterators 0))
            (set! end? true)
            (.search this 1)))))

(defn intersection [iterators]
  (if (> (alength iterators) 1)
