Avoid race condition using scan, as suggested by @robertberry