Rewrite rules and other minor fixes