Fix possible thread issues.