fix race condition