Fixing potential race condition