Refactor categories and subcategories helper