Improve the error handling.