added additional error checks.