Refactored js code and merged to the master

there is far too much reformatting to be able to easily tell if there is a logic change.