Fixed the error handling