Refactored js code and merged to the master