     var next: IntersectionNode?
     var previous: IntersectionNode?
     var edge: Edge?
-    var isIntersection: Bool
     /// links to locations on neighboring paths, indexed by path number
-    var neighbors: [Int: [IntersectionNode]] = [:]
-    init(location: IndexedPathLocation, isIntersection: Bool) {
+    var neighbors = [IntersectionNode]()
+    init(location: IndexedPathLocation) {
         self.location = location
-        self.isIntersection = isIntersection
-    }
-    func addNeighbor(_ neighbor: IntersectionNode, pathNumber: Int) {
-        if neighbors[pathNumber] == nil { neighbors[pathNumber] = [] }
-        neighbors[pathNumber]!.append(neighbor)
+    }
+    func addNeighbor(_ neighbor: IntersectionNode) {
+        guard self.neighbors.allSatisfy({ $0 !== neighbor }) else { return }
+        neighbors.append(neighbor)
+    }
+    func replaceNeighborReference(_ node: IntersectionNode, with replacement: IntersectionNode) {
+        for i in neighbors.indices where neighbors[i] === node {
+            neighbors[i] = replacement
+        }
     }
     func mergeNeighbors(of node: IntersectionNode) {
-        // TODO: point the links from node.neighbors.neighbors back to self
-
-        // point the links from self.neighbors to node.neighbors
-        for (key, value) in node.neighbors {
-            for node in value {
-                self.addNeighbor(node, pathNumber: key)
-            }
+        for neighbor in node.neighbors {
+            neighbor.replaceNeighborReference(node, with: self)
+            self.addNeighbor(neighbor)
         }
     }
 }

    /// Create the graph representing the component and return the first node (which represents the start of the first edge)
    static func createGraph(for component: PathComponent, componentIndex: Int, using intersections: [IntersectionNode]) -> IntersectionNode {
        var endCappedIntersections = intersections
        
        let startingLocation = IndexedPathLocation(componentIndex: componentIndex, elementIndex: component.startingIndexedLocation.elementIndex, t: component.startingIndexedLocation.t)
        let endingLocation = IndexedPathLocation(componentIndex: componentIndex, elementIndex: component.endingIndexedLocation.elementIndex, t: component.endingIndexedLocation.t)

        if endCappedIntersections.isEmpty || endCappedIntersections.first!.location != startingLocation {
            endCappedIntersections.insert(IntersectionNode(location: startingLocation, isIntersection: false), at: 0)
        }
        if endCappedIntersections.last!.location != endingLocation {
            endCappedIntersections.append(IntersectionNode(location: endingLocation, isIntersection: false))
        }

        for i in 0..<endCappedIntersections.count {

            let first = endCappedIntersections.first!
            first.previous = last.previous
            last.previous?.next = first
            first.mergeNeighbors(of: last)
            endCappedIntersections.removeLast()
        }
        return endCappedIntersections.first!
