refactored main.js, template.html for performance optimizations