added code for segmentation.