race condition bug fixed