Improved error message handling.