         }
 
         ctx.baq.bandwidth[read_index] = bandWidth;
+    }
+};
+
+template <target_system system>
+struct hmm_window_valid : public lambda<system>
+{
+    LAMBDA_INHERIT;
+
+    CUDA_HOST_DEVICE bool operator() (const uint32 read_index)
+    {
+        if (ctx.baq.hmm_reference_windows[read_index].x == short(-1) &&
+            ctx.baq.hmm_reference_windows[read_index].y == short(-1))
+        {
+            return false;
+        } else {
+            return true;
+        }
     }
 };
 

    struct baq_context<system>& baq = context.baq;
    vector<system, uint32>& active_baq_read_list = context.temp_u32;
    vector<system, uint32>& baq_state = context.temp_u32_2;

    // check if we can use the lmem kernel
#if ENABLE_LMEM_PATH

    baq.hmm_reference_windows.resize(batch.device.num_reads);
    baq.bandwidth.resize(batch.device.num_reads);

    // compute the HMM windows
    // note: this is used both for real BAQ and flat BAQ, so we use the full active read list
    parallel<system>::for_each(context.active_read_list.begin(),
                               context.active_read_list.end(),
                               compute_hmm_windows<system>(context, batch.device));

    // remove any reads for which we failed to compute the HMM window
    temp_active_list.resize(active_baq_read_list.size());
    num_active = parallel<system>::copy_if(active_baq_read_list.begin(),
                                           active_baq_read_list.size(),
                                           temp_active_list.begin(),
                                           hmm_window_valid<system>(context, batch.device),
                                           context.temp_storage);
    active_baq_read_list = temp_active_list;
    active_baq_read_list.resize(num_active);

    temp_active_list.resize(context.active_read_list.size());
    num_active = parallel<system>::copy_if(context.active_read_list.begin(),
                                           context.active_read_list.size(),
                                           temp_active_list.begin(),
                                           hmm_window_valid<system>(context, batch.device),
                                           context.temp_storage);
    context.active_read_list = temp_active_list;
    context.active_read_list.resize(num_active);

#if ENABLE_LMEM_PATH
    if (!baq_use_lmem)
