            (set! node (aget (.-children node) 0)))
          (set! end? (<= (alength (.-keys node)) 0)))
   (key [this]
-       (when (false? end?)
-         (aget (.-keys node) ix)))
+       (aget (.-keys node) ix))
   (val [this]
-       (when (false? end?)
-         (aget (.-vals node) ix)))
+       (aget (.-vals node) ix))
   (next [this]
-        (if (true? end?)
-          false
+        (when (false? end?)
           (if (nil? (.-children node))
-            (do
+            (let [old-node node
+                  old-ix ix]
               (set! ix (+ ix 1))
               (loop []
                 (if (>= ix (alength (.-keys node)))

;; ITERATORS
;; .key / .val return key and val currently pointed at. key may be aliased
;; On creation/reset, points to first key
;; On next, either point to next key or set .-end? true. Return (not .-end?)
;; On seek, point to first key greater than or equal to seek-key. Return (key= (.key this) seek-key)
;; NOTE iterators are not write-safe unless reset after writing

;; TODO think we might need to be able to get last key on end

(defn apply-to-iterator [iterator movements]
  (for [movement movements]
    (case (nth movement 0)
      :next (do
              (.next iterator)
              (.key iterator))
      :seek (do
              (.seek iterator (nth movement 1))
              (.key iterator)))))

(defn apply-to-elems [elems movements]
  (let [cur-elems (atom elems)]
    (for [movement movements]
      (case (nth movement 0)
        :next (do
                (swap! cur-elems rest)
                (or (first (first @cur-elems)) (first (last elems))))
        :seek (do
                (reset! cur-elems (drop-while #(key-lt (nth % 0) (nth movement 1)) elems))
                (or (first (first @cur-elems)) (first (last elems))))))))

(defn run-iterator-prop [min-keys key-len actions movements]
  (let [tree (apply-to-tree (tree min-keys key-len) actions)
