added null pointer check