added null ptr checkes