refactoring segmentation into its own module