unify the javascript code
updated documentation and some code organization