         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]
-               (when-let [[Di i D] (first xs)]
+               (if-let [[Di i D] (first xs)]
                  (if (nil? D)
                    (recur (rest xs) emap n)
                    (let [[Ei E] (sort [(emap Di) (or (emap D) n)])

  (indices [_] (range 0 (inc dim)))
  (s [_ i D] ((or (s# i) {}) D))
  (v [ds i j D]
     (when (and (element? ds D) (index? ds i) (index? ds j))
       (cond (= j (inc i)) ((or (v# i) {}) D)
             (= j (dec i)) ((or (v# j) {}) D)
             (= j i) 1


(defn r [ds i j D]
  (loop [n 1, E D]
    (if-let [F (walk ds E i j)]
      (if (= F D)
        n
        (recur (inc n) F)))))
