replaced priority queue with deque