added support for template nesting