Fix the condition and error reporting