Slightly modify the segmentation algorithm