added sorting of cats/keys