Reorganised js code
Reorganised js code