Fixing race condition