Rewrite in group, apply rewrite at the end