Refactor CriterionFactory for clarity with generics handling