Added error checks.