Added processCategories function

This function creates a nested object containing the category hierarchy.