         ipairs (map vector indices (rest indices))
         spins (fn [D] (for [[i j] ipairs] (or (v ds i j D) 0)))
         step (fn step [xs emap n]
-               (if-let [[Di i D] (first xs)]
+               (if-let [[i D] (first xs)]
                  (if (nil? D)
                    (recur (rest xs) emap n)
-                   (let [[Ei E] (sort [(emap Di) (or (emap D) n)])
+                   (let [Di (s ds i D)
+                         [Ei E] (sort [(emap Di) (or (emap D) n)])
                          head (if (= i :root) [-1 E] [(imap i) Ei E])
                          xs (rest xs)]
                      (if (not= E n)

           (seq todo-for-i)
           (let [D (first todo-for-i)
                 Di (s ds i D)
                 head [D i Di]
                 todo (if Di (vec (push-neighbors todo Di)) todo)
                 seen (conj seen (as-root Di) [D i] [Di i])]
             (lazy-seq (cons head (collect seeds-left todo seen))))

(defn traversal [ds indices seeds]
  (let [stacks (map #(vector % ()) (take 2 indices))
        queues (map #(vector % empty-queue) (drop 2 indices))
        as-root #(vector :root %)
        unseen (fn [i seen bag] (pop-while #(seen [% i]) bag))
        pop-seen #(for [[i ys] %1] (vector i (unseen i %2 ys)))
        push-neighbors #(for [[i ys] %1] (vector i (conj ys %2)))]
