Fix potential NULL pointer derefernces.