fixing segfault in mex wrapper again (not clear why the last fix got lost)
fixing more errors in mex wrapper