Preventing race condition