Updated rewrite rules and improvements to code architecture