finish flag matching