Rewriting as contextmanager