Refactoring of the javascript library. Ran javascript lint. Ignored some warnigs to keep the syntax close to the php library.