Fix SM rewrite