moved some code from mmu