fix possible concurrency issue
fixes #584