Further refactoring of segmentation