Check null pointer and  add missing reference to a variable