Rearranged order of loops, MM much faster