This needs to lock `mtx`, like above, it's the cause of the races.