some improvements to the whitespace replacement