Added support for complex templates