small fixes on sorting