Improved error handling and updated error messages.