PLD: tests for sort and refactor