Fix race conditions.