Optimizing segmentation