Correctly determines end based on sort direction.