refactor to use global queue and used word set