Formatting javascript
Wrapped keyup logic to prevent index error