Refactor memory subsystem, update comments