refactored javascript
refactored javascript a little bit