Fix race condition for handler