Fix thread safety issue.