Pull in memory code from previous version

This needs porting to the new system