race condition bug fix