Refactored Sort Command