improved matching macro