fix some concurrency bugs