small fixes to template handling