improved readability in sort function