Refactored game loop.