Corrected error logic