slight refactor, now handles text nodes