Join curve segments until the intersection is hit; Dijkstra's algorithm

I have a question about a script I’m working on.
I´m trying to join curve segments until junctions are hit.
This way I want to prepare some data I’ve got from
I need to generate joined paths between nodes.
I’m able to do the trick for a single path, but I do have some issues by introducing a further outer loop to address multiple paths.

I do have no syntax errors. I guess it is a logic error. Somehow the script does not stop to run.
If someone would review my code, I would be very happy.
Thank you very much for reading my post.
Best wishes,
Oliver (24.1 KB)
200108_00_gh-examples_join-curves-loop.3dm (38.8 KB)