race condition partly corrected