nodeType null error removed with defer