Fix thread safety.