added support for nested templates