Null pointer check to prevent log errors