refactoring memory