Fix a couple of concurrency/reentrancy problems.