fix null pointers in certain cases