Finished stitchSegmentLines function