Introduced more robust error checks.