template.mst refactor