improve the error handling