add null pointer check