Fix thread deletion