Fixing possible race condition