memory: refactor