adding error checks

this code needs to check the return code