Fix up a bunch of warnings (dead code, null pointers, and others.)