refactored continue_match function