modified error logic