Moving JS logic out of index.html