made mm function better