first version of the matching code