Refactored the javascript
Refactored the javascript