race condition bug-fix