Fixed an issue with error handling