         :else (recur (walk ds E j i))))))
 
 (defn orbit-loopless? [ds indices D]
-  (empty? (for [[D i] (traversal ds indices [D])
-                :when (and (not= i :root) (or (nil? D) (= D (s ds i D))))]
+  (empty? (for [[i E] (traversal ds indices [D])
+                :when (and (not= i :root) (or (nil? E) (= E (s ds i E))))]
             D)))
 
 (defn curvature


(defn orbit-reps
  ([ds indices seeds]
    (for [[D i] (traversal ds indices seeds) :when (= :root i)] D))
  ([ds indices]
    (orbit-reps ds indices (elements ds))))

(defn orbit-elements [ds indices seed]
  (distinct (for [[_ i D] (traversal ds indices [seed])] D)))

(defn connected? [ds]
  (> 2 (count (orbit-reps ds (indices ds)))))

(defn partial-orientation [ds]
  (loop [ori {}
         [[Di i D] & xs] (traversal ds (indices ds) (elements ds))]
    (cond (nil? i) ori
          (or (nil? D) (ori D)) (recur ori xs)
          :else (recur (assoc ori D (if (= :root i) 1 (- (ori Di)))) xs))))

(defn loopless? [ds]
  (every? (fn [[i D]] (not= D (s ds i D)))

        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 [[i D] (first xs)]
                 (if (nil? D)
                   (recur (rest xs) emap 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)
