rewrote the part in cut_text that searched the nearest span to be simpler, it corrected a bug too.