cleanup & added basic segmentation code