Fixed a race condition bug.