Fixed a race condition issue.