add extra checks to mex file