Fix thread-unsafe bug.