Did some general cleanup of the javascript.
The script now uses ES5 strict mode without error.
Various refactoring improvements.
Code organization improved
Added a bunch of documentation