adding error logic