Add MemoryRegion, do some refactoring