Added rewrite registering and flushing on activation