General code clean up

Hello Drew,

this pull request is attempting to clean up some code in `main.js`.
If you’re not happy with the changes, I’ll revert them. The reason
I didn’t remove unused code is that you might want to use it for
features that aren’t implemented yet.