Merged in changes to mem and prefmem from 9.4 branch.  Passes unit tests.