fix matlab bugs