Function match was modified to make it simpler