refactor templating to make it more modular