Improved error handling.