Fix bug in template costing

Cost was being computed for each template point, instead of for the whole template.