added most of the code for categories