Fix race conditions, tests.