Improve race condition fix