def resampling_panel(resampling_records, is_sorted=False):
    """Converts a simple collection of resampling records into a list of
    elements corresponding to cycles. It is like doing a pivot on
    the step indices into an extra dimension. Hence it can be
    thought of as a list of tables indexed by the cycle, hence the
    name panel.

    """
    res_panel = []
    if not is_sorted:
        resampling_records.sort()
    rec_it = iter(resampling_records)
    last_cycle_idx = None
    cycle_recs = []
    stop = False
    while not stop:
        cycle_stop = False
        while not cycle_stop:
            try:
                rec = next(rec_it)
            except StopIteration:
                stop = True
                cycle_stop = True
                curr_cycle_recs = cycle_recs
            else:
                if last_cycle_idx is None:
                    last_cycle_idx = rec.cycle_idx
                if rec.cycle_idx > last_cycle_idx:
                    cycle_stop = True
                    curr_cycle_recs = cycle_recs
                    cycle_recs = [rec]
                    last_cycle_idx += 1
            if not cycle_stop:
                cycle_recs.append(rec)
            else:
                cycle_table = []
                step_recs = []
                step_idx = 0
                step_stop = False
                cycle_it = iter(curr_cycle_recs)
                while not step_stop:
                    try:
                        cycle_rec = next(cycle_it)
                    except StopIteration:
                        step_stop = True
                        curr_step_recs = step_recs
                    else:
                        if cycle_rec.step_idx > step_idx:
                            step_stop = True
                            curr_step_recs = step_recs
                            step_recs = [cycle_rec]
                            step_idx += 1
                    if not step_stop:
                        step_recs.append(cycle_rec)
                    else:
                        step_row = [None for _ in range(len(curr_step_recs))]
                        for walker_rec in curr_step_recs:
                            walker_idx = walker_rec.walker_idx
                            decision_id = walker_rec.decision_id
                            instruction = walker_rec.target_idxs
                            step_row[walker_idx] = decision_id, instruction
                        cycle_table.append(step_row)
        res_panel.append(cycle_table)
    return res_panel
