A rewrite of memory.js to be actually readable.