fix potential race conditions
merge