ver 2 of segmentation algo