diff --git a/src/sgcocaller/utils.nim b/src/sgcocaller/utils.nim
index 9935127f27f732f768cfb897c54d3fd84225b7f9..86d13bf313d209deedf70ac39e43adc5f0071c04 100755
--- a/src/sgcocaller/utils.nim
+++ b/src/sgcocaller/utils.nim
@@ -67,8 +67,9 @@ proc get_base_offset*(position:int, align: Record): int =
     if off <= position:
       continue
     over = off - position
-    # get the base 
-    base_offset = qoff - over-1
+    base_offset = qoff - over - 1
+    if($event.op == 'N') or ($event.op == 'D') or ($event.op == 'H'): 
+      base_offset = -1
     break 
   return base_offset    
 
@@ -147,6 +148,8 @@ proc countAllele*(ibam:Bam, maxTotalReads:int,
     if not barcodeTable.hasKey(currentCB): continue
     base_off = get_base_offset(position = stopPos, align = aln) 
     base = aln.base_at(base_off)
+    if base_off < 0:
+      continue
     if aln.base_quality_at(base_off).cint < minbsq: 
       continue
     total_reads+=1