refactroring to dynamically add rewrite rules