Improved authentication handling.