Moving category tree logic to model