Updated logic for categories.