Added logic for hand sorting