Added some error checks.