multiset match bug fix
loop function