Fix error logic