moved code from mmm repo here