Refactor facet code