refactor range_entries and rev_range_entries