implement a better game loop