             let nextE: Edge
             let nextJ: Junction
             
-            if let J = junctions.first(where: { $0.edge1 == e } ) {
+            let match1 = { (J: Junction) in J != e.from && J.edge1 == e }
+            let match3 = { (J: Junction) in J != e.from && J.edge3 == e }
+
+            if let J = junctions.first(where: match1) {
                 nextJ = J
                 nextE = J.edge3
-            } else if let J = junctions.first(where: { $0.edge3 == e } ) {
+            } else if let J = junctions.first(where: match3) {
                 nextJ = J
                 nextE = J.edge1
             } else {

        }
        
        self.init(name: (name ?? "L"), junctions: junctions)
    }
    
    public static var empty: Link {

        self.junctions = junctions
    }
    
    public init(name: String? = nil, planarCode: [(Int, Int, Int, Int)]) {
        
        // generate edges.
        
