Added null pointer check.