   "Counts the sub-crossings that result from adding a single sub-edge
   to the accumulator tree"
   ([tree index]
-     (single-edge-sub-crossings tree index 0))
+   (single-edge-sub-crossings tree index 0))
   ([tree index crossings]
-     (if (zero? index)
-       [tree crossings]
-       (let [parent-index (quot (dec index) 2)
-             real-right-index parent-index]
-         (if (odd? index)
-           (recur tree parent-index (+ crossings (get tree real-right-index)))
-           (recur (update-in tree [real-right-index] inc) parent-index crossings))))))
+   (if (zero? index)
+     [tree crossings]
+     (let [parent-index (quot (dec index) 2)
+           real-right-index parent-index]
+       (if (odd? index)
+         (recur tree parent-index (+ crossings (get tree real-right-index)))
+         (recur (update-in tree [real-right-index] inc) parent-index crossings))))))
 
 
 (defn count-sub-crossings-single-node

                                     minus-ps minus-qs)
                                (apply map vector))]
    (map->CountedAndMarkedGraph (assoc ordered-graph
                                      :crossings (reduce + crossings)
                                      :marked (reduce set/union marked)))))


(defn best-ordering

  [graph node]
  (loop [graph graph
         characters (:characters node)]
    (if (empty? characters)
      graph
      (let [character (first characters)
            last-node (-> graph :last-nodes-by-character character)
            [g c] (if last-node
                    (let [last-node-characters (-> graph
                                                   :last-nodes-by-node
                                                   ((:id last-node) #{}))
                          edge-characters (vec (set/intersection last-node-characters characters))
                          g (process-edge-characters graph last-node node edge-characters)]
                      [g (set/difference characters last-node-characters)])
                    [graph (disj characters character)])]
        (recur g c)))))


(defn add-node
