add mex building system & add_diag (tested)