<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def old_roles_manager(self):
        '''Return old roles, grouped first by term, then by chamber,
        then by type.'''
        wrapper = self._old_role_wrapper
        chamber_getter = operator.methodcaller('get', 'chamber')
        for term, roles in self.get('old_roles', {}).items():
            chamber_roles = defaultdict(lambda: defaultdict(list))
            for chamber, roles in itertools.groupby(roles, chamber_getter):
                for role in roles:
                    role = wrapper(role)
                    typeslug = role['type'].lower().replace(' ', '_')
                    chamber_roles[chamber][typeslug].append(role)
            yield term, chamber_roles