fixed some error logic