Minor improvements to the error handling