             case cigar_event::M:
                 if (update_qualities)
                 {
-                    const uint32 expectedPos = refI - refOffset + (i - numD - baq_start - readI);
+                    const uint32 expectedPos = refI - refOffset + (i - numD - baq_start - readI) + read_shift;
                     ctx.baq.qualities[qual_idx] = capBaseByBAQ(batch.qualities[idx.qual_start + read_bp_idx],
                                                                ctx.baq.qualities[idx.qual_start + read_bp_idx],
                                                                baq_state[idx.qual_start + read_bp_idx],

        if (hmm_reference_window.x < 0 && batch.alignment_start[read_index] < abs(hmm_reference_window.x))
        {
            hmm_reference_offset = 0;
            referenceLength -= abs(hmm_reference_window.x);
        } else {
            hmm_reference_offset = batch.alignment_start[read_index] + hmm_reference_window.x;
        }


        // compute the shift applied to the reference during BAQ setup
        // this happens if the computed HMM window start lies before the chromosome start (i.e., the start coordinate is negative)
        // also computes the shift in expected read BP positions that is present in the BAQ state vector
        int16 reference_shift, read_shift;
        if (hmm_reference_window.x < 0 && batch.alignment_start[read_index] < abs(hmm_reference_window.x))
        {
            reference_shift = abs(hmm_reference_window.x);
            read_shift = batch.alignment_start[read_index];
        } else {
            reference_shift = 0;
            read_shift = 0;
        }

        // compute the reference window offset
