fixed possible race condition