Updated match function