refactoring templates to move all js code to main.js