fix racing condition bug