Avoid NULL pointer dereferencing