Fixed a few shutdown-related errors

`Matlab` should now shut down more reliably on deletion.