Refactored main.js
Fixes