Simplify code.
Rework shorten_string, which had pathological behaviour if no space could be found near the wanted splitting point.
Add tests for it too.