add a few missing null pointer checks, and fix check vs dereference order in some...