added support for templates and merge vars