Refactored js code and merged to the master

I will remove