race condition fixes