Fix error logic bug