added segmentation code