Main rewrite