Minor cleanup.
Fix bugs in joining paths to create a loop.