Correct loose loop condition
Factor out Util and Segment classes
Get basic segmentation working