fix descending custom sorting (and simplified the code a little bit)