Fix possible null pointer dereference