Resolving issue with the segment sandwiched between 2 loops