improve the tmpl function