rewrite matching func