added nullptr check