 template <target_system system>
 struct cap_baq_qualities : public lambda<system>
 {
+    LAMBDA_INHERIT;
+
     typename vector<system, uint32>::view baq_state;
 
     cap_baq_qualities(typename firepony_context<system>::view ctx,

        return b;
    }

    // xxxnsubtil: this could use some cleanup
    CUDA_HOST_DEVICE void operator() (const uint32 read_index)
    {
        auto& ctx = this->ctx;
        auto& batch = this->batch;

        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];

        const ushort2& read_window = ctx.cigar.read_window_clipped[read_index];
        const ushort2& read_window_no_insertions = ctx.cigar.read_window_clipped_no_insertions[read_index];
        const ushort2& reference_window = ctx.cigar.reference_window_clipped[read_index];

        const uint32 seq_to_alignment_offset = batch.alignment_start[read_index];
        const uint32 first_insertion_offset = read_window_no_insertions.x - read_window.x;

        const int offset = MIN_BAND_WIDTH / 2;

        const uint32 readStart = reference_window.x + seq_to_alignment_offset;
        const uint32 start = max(readStart - offset - first_insertion_offset, 0u);

        const int refOffset = (int)(start - readStart);

        uint32 readI = 0;
        uint32 refI = 0;
        uint32 current_op_offset = 0;
        uint32 numD = 0;

        // scan for the start of the baq region
        uint32 i;
        for(i = 0; i < cigar_end - cigar_start; i++)
        {
            const uint16 read_bp_idx = ctx.cigar.cigar_event_read_coordinates[cigar_start + i];
            if (read_bp_idx != uint16(-1) && read_bp_idx >= read_window.x)
                break;
        }



        // get the windows for the current read
        const uint2& reference_window = ctx.baq.reference_windows[read_index];
        const ushort2& read_window_clipped = ctx.cigar.read_window_clipped[read_index];

        referenceStart = reference_window.x;
        referenceLength = reference_window.y - reference_window.x + 1;

        queryStart = read_window_clipped.x;
        queryEnd = read_window_clipped.y;
        queryLen = queryEnd - queryStart + 1;

        bandWidth = ctx.baq.bandwidth[read_index];
        bandWidth2 = bandWidth * 2 + 1;
