     /// 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))
+        if endCappedIntersections.first?.location != startingLocation {
+            endCappedIntersections.insert(IntersectionNode(location: startingLocation), at: 0)
+        }
+        if endCappedIntersections.last?.location != endingLocation {
+            endCappedIntersections.append(IntersectionNode(location: endingLocation))
         }
 
         for i in 0..<endCappedIntersections.count {

        var path1Intersections: [IntersectionNode] = []
        var path2Intersections: [IntersectionNode] = []
        intersections.forEach {
            let node1 = IntersectionNode(location: $0.indexedPathLocation1, isIntersection: true)
            let node2 = IntersectionNode(location: $0.indexedPathLocation2, isIntersection: true)
            node1.addNeighbor(node2, pathNumber: 1)
            node2.addNeighbor(node1, pathNumber: 0)
            path1Intersections.append(node1)
            if operation != .removeCrossings {
                path2Intersections.append(node2)
            } else {
                path1Intersections.append(node1)
            }
        }
        AugmentedGraph.sortAndMergeDuplicates(of: &path1Intersections)

    private func createComponent(from node: IntersectionNode) -> PathComponent {
        var points: [CGPoint] = [node.edge!.component.startingPoint]
        var orders = [Int]()
        func visit(from node: IntersectionNode) -> IntersectionNode? {
            guard let forwardEdge = node.edge else {
                assertionFailure("consistency failure")
                return nil
            }
            guard let backwardsEdge = node.previous?.edge else {
                assertionFailure("consistency failure")
                return nil
            }
            if forwardEdge.inSolution, forwardEdge.visited == false {
                visit(forwardEdge.component)
                forwardEdge.visited = true
                return node.next
            } else if backwardsEdge.inSolution, backwardsEdge.visited == false {
                visit(backwardsEdge.component.reversed())
                backwardsEdge.visited = true
                return node.previous
            } else {
                return nil
            }
        }
        func visit(_ component: PathComponent) {
            points += component.points[1..<component.points.count]
            orders += component.orders
        }

        var nextNode: IntersectionNode? = node
        while let currentNode = nextNode {
            nextNode = nil
            if let temp = visit(from: currentNode) {
                nextNode = temp
            } else {
                for neighbor in currentNode.neighbors {
                    if let temp = visit(from: neighbor) {
                        nextNode = temp
                        break
                    }
                }
            }
        }

        if points.last != points.first {
            points.append(points.first!)
            orders.append(1)
        }

        return PathComponent(points: points, orders: orders)
