Significantly clean up.

Did a significantly clean up, changed the code structure also improved the documentation. Now it's ready to be ported to AMD or CommonJS.