Add null pointer check