reroute function

Change terminal nodes of edges