convert Mex into MesoA plus minor edits