rewrite mex file