More overlapping fixes for #244

Better overlap detection.
Better handling of mode switching.
Conversion of previously overlapping entities to actual tags, if
possible, when switching modes.