added segmentation algorithm