Sort categories properly