improved rewrite rules