Improved error checks.