fixed some newly introduced rewriting issues