 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,


    CUDA_HOST_DEVICE void operator() (const uint32 read_index)
    {
        uint2   hmm_reference_window;

        // grab reference sequence window in the genome
        const uint32 ref_ID = batch.chromosome[read_index];
        const uint32 ref_base = ctx.reference.sequence_bp_start[ref_ID];
        const uint32 ref_length = ctx.reference.sequence_bp_len[ref_ID];

        const uint32 seq_to_alignment_offset = batch.alignment_start[read_index];

        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 first_insertion_offset = read_window_no_insertions.x - read_window.x;
        const uint32 last_insertion_offset = read_window.y - read_window_no_insertions.y;

        const int offset = MIN_BAND_WIDTH / 2;
        uint32 readStart = reference_window.x + seq_to_alignment_offset; // always clipped

        // reference window for HMM
        uint32 start = max(readStart - offset - first_insertion_offset, 0u);
        uint32 stop = reference_window.y + seq_to_alignment_offset + offset + last_insertion_offset;

        if (stop > ref_length)
        {
            hmm_reference_window = make_uint2(uint32(-1), uint32(-1));
            return;
        }

        start += ref_base;
        stop += ref_base;

        hmm_reference_window = make_uint2(start, stop);
        ctx.baq.reference_windows[read_index] = hmm_reference_window;

        // compute the band width
        int referenceLength;
        int queryLen;

        referenceLength = hmm_reference_window.y - hmm_reference_window.x + 1;
        queryLen = read_window.y - read_window.x + 1;

        uint16 bandWidth;

        if (referenceLength > queryLen)
            bandWidth = referenceLength;
        else
            bandWidth = queryLen;

        if (MIN_BAND_WIDTH < abs(referenceLength - queryLen))
        {
            bandWidth = abs(referenceLength - queryLen) + 3;
        }

        if (bandWidth > MIN_BAND_WIDTH)
            bandWidth = MIN_BAND_WIDTH;

        if (bandWidth < abs(referenceLength - queryLen))
        {
            bandWidth = abs(referenceLength - queryLen);
        }

        ctx.baq.bandwidth[read_index] = bandWidth;


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