some modifications before rewrite