Some refactoring of segmentation