added proper support for templates.