Fixed a race-condition problem