Fixes and rewamp of main.js