Fixed some concurrency problems