Consolidated code and documentation

Consolidated code structure, updated and added code documentation to allow generating a proper documentation using JSDuck.
Do you have an idea why the implementation was like this, with these strange tiny functions?