I'd like to factor out the common code between here and the `classesmatching` function