Bunch of code cleanup

Removed some unnecessary things, moved common functions into a common.js file, cleaned up some syntax

No actual new functionality