Fix concurrency problem

Ref #443