In some cases the last point of the previous segment also gets added as the first point of the new segment, leading to a messed up track.