Fixing the error handling