fixing segfault in mex wrapper