Improved mode handling.