Added missing null pointer check