Refactored js code and merged to the master

ok, I will move it