Optimized prefix/suffix filter so that it only calculates the values for the reference sequence region of interest