Refactor faceting, add tests