Completed adaptSegments and testAdaptSegments