Refactor memory collection