finish MA function