refactor templating