Finished refactor of segmentation