Move the gameloop to a seperate function