added some error checks