Fixed race condition is js