Overhaul of the rewrite rules