minor refactoring to mem mgmt