added null ptr check