Added null ptr checks