Changed the nodetype == 3 checks to a global function isTextNode