Refactored js code and merged to the master

spaces please