A bunch of improvements

* Simplified the code in a bunch of places
* Reduced the size of the minified code.
* Cleaned up the comments.