Added various null ptr checks