Added pattern grouping logic + tests. Tidy up of some existing Predicate-related tests