fixed bug with finding the length of the segment