Stage 1 of rewrite