Redesigned main game loop to make it easier to drive.