Fix thread issues when quitting.