refactored js in index.html