Rewrite substitution