Built recursive function for listing all categories in a tree structure