refactor match_range