NULL pointer dereference fix