Mostly fixing race conditions