Fix a few thread-safety/concurrency issues