improve handling of text nodes