edited the segmentation code