                     break;
 
                 if (ctx.cigar.cigar_events[ev] == cigar_event::I)
-                    num_insertions++;
+                    indel_offset++;
 
                 if (ctx.cigar.cigar_events[ev] == cigar_event::D)
-                    num_deletions++;
+                    indel_offset--;
             }
 
-
-            // xxxnsubtil: this might be wrong if there are indels within the feature range!
-            for(uint32 dead_bp = uint32(start) + num_insertions - num_deletions; dead_bp <= uint32(end) + num_insertions - num_deletions; dead_bp++)
+            // xxxnsubtil: this assumes there are no indels inside the feature itself!
+            start += indel_offset;
+            end += indel_offset;
+
+            // if both start and end are behind the start of the read window...
+            if ((start < read_window_clipped.x && end < read_window_clipped.x) ||
+                    // or both are beyond the end of the read window...
+                    (start > read_window_clipped.y && end > read_window_clipped.y))
+            {
+                // ... then there's nothing to do
+                continue;
+            }
+
+            // truncate any portions of the feature range that fall outside the clipped read region
+            start = max(start, read_window_clipped.x);
+            start = min(start, read_window_clipped.y);
+            end = max(end, read_window_clipped.x);
+            end = min(end, read_window_clipped.y);
+
+            for(uint32 dead_bp = uint32(start); dead_bp <= uint32(end); dead_bp++)
                 ctx.active_location_list[idx.read_start + dead_bp] = 0;
         }
     }


        uint2 vcf_db_range = ctx.snp_filter.active_vcf_ranges[read_index];



        // traverse the VCF range and mark corresponding read BPs as inactive
        for(uint32 feature = vcf_db_range.x; feature <= vcf_db_range.y; feature++)
        {

            int start = db.reference_window_start[feature] - ref_sequence_offset + read_window_clipped.x;
            int end = db.reference_window_start[feature] + db.alignment_window_len[feature] - ref_sequence_offset + read_window_clipped.x;

            // adjust feature range for indels
            // feature coordinates are expressed in terms of the reference sequence
            // every insertion to the reference shifts the corresponding read coordinate forward
            // every deletion shifts the read coordinate backward
            int indel_offset = 0;

            const uint32 cigar_start = ctx.cigar.cigar_offsets[idx.cigar_start];
            for(uint32 ev = cigar_start + read_window_clipped.x; ev < cigar_start + read_window_clipped.y; ev++)
