fix a few nil dereferences, etc