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