Refactor hand sorting