Added globalMatch() and simplified flag-related code.