fixes if-logic for error condition