Splitting and merging text segments