WIP - major refactoring and modularization

All current modules are in one file.

TODO:

 - fix errors
 - split up in multiple files
 - find more modules
 - refactor further
 - make use of dependency manager like browserify
 - write unit tests for modules