refactor text segment