Make Rewrite layer pluggable

Initial review draft. Adding Tests for new code are still pending. Am working on them Existing tests are passing.
if this is a constant pls make is private static final and all caps