Changing data structure to priority queue.