Refactor JS out of index.html