segmentation functionality working. major cleanup