ensure categories are sorted properly