refactor text node handlers