fixed race condition bug