improved synchronization of main game loop