refactoring template from scratch