Added better support for potential nullptr

Change-Id: I08301cdf990ed316bd42ca9126237dc1c510f284