fix error logic