Modularize the JavaScript.  This will break up the code into separate files while having only one global.
Fix bugs from Module refactor. Add comments for clarity now that things are really broken out.