Update main.js

fixed a few bugs