                              #{}))
                   g (update-in graph [:marked] set/union marked)]
               (recur g tree parent-index c))
-            (let [t (-> tree
-                        (update-in [real-right-index :weight] + weight)
+            (let [t (-> (update-in tree [real-right-index :weight] + weight)
                         (cond->
                          is-seg-c (assoc-in [real-right-index :is-seg-c] true)
                          (not is-seg-c) (update-in [real-right-index :node-edges]

  of [order edge] pairs of the edge targets in the destination layer, using
  this edge ordering"
  [ordered next-ordered graph-edges]
  (let [next-order-map (->> next-ordered
                            (map-indexed #(-> [%2 %1]))
                            (into {}))
        ;; Edges between segment containers need to be counted as well
        ;; but they change with each new ordering, so we just temporarily
        ;; merge the current segment edges with the never-changing
        ;; node -> node edges
        edges (->> next-ordered
                   (filter vector?)
                   (map (juxt identity
                              (partial mapcat #(-> % :characters))))
                   (map (fn [[seg-c characters]]

    (if (< num-succs 2)
      0
      (let [measures (:measures next-layer)
            order-map (->> (sort-by #(get measures %) succs)
                           (map-indexed (fn [idx n]
                                          (map #(-> [% idx])
                                               (:characters n))))
