Add some defensive checks.