Fixed deadlock on closing the application