Fix my broken NULL pointer check (and some segfaults).