slightly smarter template processing