Move functions out of index.html