fixing issue with dereferencing possibly null pointer