Merge pmm-enhance back into master

singerng and I have finished optimizing the PMM code for memory efficiency, meaning it's now ready to be merged back into master.