Added null pointer check