rewriting dynamic memory