fix possible concurrency issue
fixes #509