                         (if (empty? (:segments seg-c))
                           (recur (rest f) seg-c (conj layer item))
                           (recur (rest f) (first segment-containers) (conj layer seg-c item)))))))]
-    (assoc next-layer :plus-qs plus-qs)))
-
-
-(defn ensure-alternating
-  "Step 6 of ESK, ensure that the resulting layer is alternating. We do this in a
-  different order than the paper first because we can due to not working with
-  mutable state, and second because it just flows better this way. Specifically, it
-  is conceptually easier to think of it as an algorithm for taking one alternating
-  layer and using it to produce the next alternating layer in the graph (steps 1-4, 6),
-  and then a separate algorithm that counts the crossings that result from the
-  orderings on those two layers (step 5)."
-  [next-layer]
-  (->> (:plus-qs next-layer)
-       (partition-by #(instance? SegmentContainer %))
-       (mapcat (fn [items]
-                 (if (instance? SegmentContainer (first items))
-                   [(reduce #(update-in %1 [:segments] rrb/catvec (:segments %2))
-                            items)]
-                   (interpose (first segment-containers) items))))
-       vec
-       (#(if (instance? SegmentContainer (first %))
-           %
-           (rrb/catvec (vec (take 1 segment-containers)) %)))
-       (#(if (instance? SegmentContainer (peek %))
-           %
-           (rrb/catvec % (vec (take 1 segment-containers)))))
-       (assoc next-layer :alternating)))
-
+    (assoc next-layer :ordered ordered)))
 
 
 (defn- sorted-edge-order

              ordered-graph (-> (if reverse?
                                  (reverse-graph sparse-graph)
                                  sparse-graph)
                                (update-in [:layers 0] assoc :alternating alternating)
                                order-graph-once)]
          (println c (:crossings ordered-graph) (-> ordered-graph :layers peek :alternating))
          (recur (-> ordered-graph :layers peek :alternating)
                 (conj orderings (if reverse? (reverse-graph ordered-graph) ordered-graph))))))))

                            (set-qs-non-qs graph)
                            (set-measures graph layer)
                            (order-next-layer layer)
                            add-qs)
            [marked-graph crossings] (count-crossings graph layer next-layer)
            g (-> marked-graph
                  (update-in [:crossings] + crossings)
