add NULL pointer check