fixed bug in match function