working Knuth-Plass implementation