Fix some races and simplify things.