Refactor memory to use a HashMap