restructred a large portion of the javascript
Removed unused js