         const uint32 reference_alignment_start = seq_base + align_offset;
 
         uint16 current_bp_idx = 0;
-        uint16 num_snps = 0;
+        uint16 num_errors = 0;
 
         // go through the cigar events looking for the event we're interested in
-        for(uint32 i = cigar_start; i < cigar_end; i++)
-        {
-            switch(ctx.cigar.cigar_events[i])
+        for(uint32 event = idx.cigar_start; event < idx.cigar_start + idx.cigar_len; event++)
+        {
+            // figure out the cigar event range for this event
+            const uint32 cigar_start = ctx.cigar.cigar_offsets[event];
+            const uint32 cigar_end = ctx.cigar.cigar_offsets[event+1];
+
+            switch(batch.cigars[event].op)
             {
-            case cigar_event::M:
+            case cigar_op::OP_M:
+
+                for(uint32 i = cigar_start; i < cigar_end; i++)
                 {
                     // update the current read bp index
                     current_bp_idx = ctx.cigar.cigar_event_read_coordinates[i];

                    if (reference_bp != read_bp)
                    {
                        ctx.cigar.is_snp[idx.read_start + current_bp_idx] = 1;
                        num_snps++;
                    }
                }

                break;

            case cigar_event::I:
                // update the current read bp index
                current_bp_idx = ctx.cigar.cigar_event_read_coordinates[i];
                ctx.cigar.is_insertion[idx.read_start + current_bp_idx] = 1;
                break;

            case cigar_event::D:
                // note: deletions do not exist in the read, so current_bp_idx is not updated here
                // this marks the read bp where a deletion begins
                // (this implies that a given bp can have both is_deletion and one of is_insertion or is_snp set)
                ctx.cigar.is_deletion[idx.read_start + current_bp_idx] = 1;
                break;
            }
        }

        ctx.cigar.num_errors[read_index] = num_snps;
    }
};

struct count_indels : public bqsr_lambda
{
    count_indels(bqsr_context::view ctx,
                 const alignment_batch_device::const_view batch)
        : bqsr_lambda(ctx, batch)
    { }

    CUDA_HOST_DEVICE void operator() (const uint32 read_index)
    {
        const CRQ_index idx = batch.crq_index(read_index);
        const uint32 cigar_start = ctx.cigar.cigar_offsets[idx.cigar_start];
        const uint32 cigar_end = ctx.cigar.cigar_offsets[idx.cigar_start + idx.cigar_len];

        uint32 sum = 0;
        for(uint32 i = cigar_start; i < cigar_end; i++)
        {
            if (ctx.cigar.cigar_events[i] == cigar_event::I ||
                ctx.cigar.cigar_events[i] == cigar_event::D)
            {
                sum++;
            }
        }

        ctx.cigar.num_errors[read_index] += sum;
    }
};


                     cigar_coordinates_expand(*context, batch.device));

    // compute the error bit vectors
    // this also counts the number of errors in each read
    thrust::for_each(context->active_read_list.begin(),
                     context->active_read_list.end(),
                     compute_error_vectors(*context, batch.device));
}

void debug_cigar(bqsr_context *context, const alignment_batch& batch, int read_index)
