finally fix race condition