introduced some error checks