Fix race issues