refactored javascript
working on timer