Moved some utility code out of the model into TemplateTracker and SegmentationHelper, where it belonged.