add a null pointer check