fixing race condition