adding null pointer check