bugfix in rewriteRightEnds