finish the logic of bracketmatch