fixed a race condition.