refactor templates.js into own module