Bugfixes: on quit and segfault on exit