Fix a couple of concurrency problems