Template/JavaScript refactoring