fixes for NULL pointers to avoid crashes