Improve the error handling