Moved MMR code to its own module and tweaks