fixing race-condition