Working on the logic for the matching