Fixed bug in game loop