Optimized the controller main loop.