fixed a race condition