Fixed a couple of concurrency issues