def group_changes(changes):
    """Consolidate same-position insertions and deletions into single changes.
    """
    insertions = [c for c in changes if c.change_type == 'insert']
    deletions = [c for c in changes if c.change_type == 'delete']
    mutations = [c for c in changes if c.change_type == 'mutate']
    inserted_locations = [ins.position for ins in insertions]

    grouped_insertions = []
    for i, ins in enumerate(insertions):
        if i > 0:
            if ins.position == insertions[i-1].position:
                grouped_insertions[-1].output_material += ins.output_material
                continue
        grouped_insertions.append(ins)


    grouped_deletions = []
    for i, dlt in enumerate(deletions):
        if i > 0:
            if dlt.position == deletions[i-1].position+2 and dlt.position-1 not in inserted_locations:
                grouped_deletions[-1].input_material += dlt.input_material
                continue
        grouped_deletions.append(dlt)

    return sorted(grouped_insertions + grouped_deletions + mutations, key=lambda x: x.position)