Changed gameLoop to a function and fixed a few global variables