Add a few defensive programming check.