DRY up the javascript in index.html