Change argument order to allow using external sort instead of heapq