refactor template.js into a class