first part of a matching optimisation