Fixed thread safety issue.