Ver 3 of segmentation algo