Templating refactor