Rework saving of category counts to DB