Refactored main.js

Consolidated