More fixes for race conditions