refactor text diffing code