Refactored Sort.