Implement some rewrite rules