Race condition fixes