Using a LinkedHashSet and a PriorityQueue, instead of a HashSet and a TreeMap