Fixed deadlock when quitting app