Fixing terminating threads