Fix possible memory corruption bug.
Fix bug with hyperedge rerouting creating incorrect paths.