rewrite based on before