added error logic