refactored and generalised some of the facet processing