Fix a logical error in two if-clauses