         func drawGraph(_ graph: PathGraph) {
             for i in 0..<graph.components.count {
                 graph.components[i].forEachNode { node, _ in
+                    guard let nextNode = node.next else { return }
                     switch node.edge.inSolution {
                     case true:
                         Draw.setColor(context, color: Draw.red)
                     case false:
                         Draw.setColor(context, color: Draw.green)
                     }
-                    for curve in node.component.curves {
+                    for curve in node.forwardComponent(to: nextNode).curves {
                         Draw.drawCurve(context, curve: curve)
                     }
                 }

    func classifyEdges(for graph: PathGraph, isForFirstPath: Bool) {
        func classifyEdge(for node: Node) {
            // TODO: we use a crummy point location
            let nextEdge = node.component.element(at: 0)
            let point = nextEdge.compute(0.5)
            let normal = nextEdge.normal(0.5)
            let smallDistance = CGFloat(Utils.epsilon)

        nodes = duplicatesRemoved
    }
    func createComponent(from startingNode: Node) -> PathComponent {
        let firstPoint = startingNode.pathComponent.point(at: startingNode.componentLocation)
        var points: [CGPoint] = [firstPoint]
        var orders: [Int] = []
        func visit(from node: Node) -> Node? {
            if let next = node.next {
                let forwardEdge = node.edge
                if forwardEdge.inSolution, forwardEdge.visited == false {
                    let component = node.forwardComponent(to: next)
                    visit(component)
                    forwardEdge.visited = true
                    return next
                }
            } else {
                assert(node.pathComponent.isClosed == false, "expected next node to exist")
            }
            if let previous = node.previous {
                let backwardsEdge = previous.edge
                if backwardsEdge.inSolution, backwardsEdge.visited == false {
                    let component = node.backwardComponent(to: previous)
                    visit(component)
                    backwardsEdge.visited = true
                    return previous
                }
            } else {
                assert(node.pathComponent.isClosed == false, "expected previous node to exist")
            }
            return nil
        }
