Add a few defensive programming checks.