   adding right siblings, for a total count of edges that cross this one"
   [layer tree orig-index edge]
   (let [weight (count (:characters edge))
-        is-seg-c (instance? SegmentContainer edge)]
+        is-seg-c (instance? SegmentContainer (:dest edge))]
     (loop [layer layer
            tree tree
            index orig-index

                        (update-in [index :weight] + weight)
                        (cond->
                         is-seg-c (assoc-in [index :is-seg-c] true)
                         (not is-seg-c) (update-in [index :node-edges] conj edge)))]
              (recur layer t parent-index crossings))))))))





(defrecord Node [id layer-id characters])
(defrecord Edge [src dest characters])
(defrecord Layer [id duration nodes marked])
(defrecord SegmentContainer [segments])
(defrecord Segment [edge])
