Moved game loop to its own function