node.ownerDocument returns null if node is a document
fix node type checking