tmpl code clean up