Improvements to segmentation and template-making