Move script into its own file and fix window.setInterval bug