Fixed a thread safety issue.