fix race condition problem