Fix issue with temp files
Fix a few segfaults on linux