small fixes in sorting