Changes to rewriting behaviour to fix odd rewriting glitch.