Refactored main.js and index.html