Added logic to support remote sorting.