I know the way of doing this is to create a function and then run that function from within it's own function each time there is a sub category.
I don't really understand this so want to do some research, what's this called again so I can google some tutorials.
Any recommended links would be good also.