Refactoring templating phase