Refactor + add segmentation