refactored memory manager