Beginning cleanup after huge structural change

Now r.js is being used for the build, the previous module pattern is no longer being used, and as a result there are features that are not completed, and some variables that are polluting the global scope.

Also, comments need to be added throughout.