Update main.js

Fixed many bugs.