added error checks
added error checks