Refactoring handlebars js logic.