Fixed deadlock + crash on quit.