public static CRISPR scanRight(CRISPR candidateCRISPR, String pattern, int minSpacerLength, int scanRange, SearchUtil searchUtil)
   {
      int numRepeats = candidateCRISPR.numRepeats();
      int patternLength = pattern.length();
      int sequenceLength = DNASequence.seq.length();

      int lastRepeatIndex = candidateCRISPR.repeatAt(numRepeats-1);
      int secondToLastRepeatIndex = candidateCRISPR.repeatAt(numRepeats-2);
      int repeatSpacing = lastRepeatIndex - secondToLastRepeatIndex;

      int candidateRepeatIndex, beginSearch, endSearch, position;
      String text = "";

      boolean moreToSearch = true;
      while (moreToSearch)
      {
         candidateRepeatIndex = lastRepeatIndex + repeatSpacing;
         beginSearch = candidateRepeatIndex - scanRange;
         endSearch = candidateRepeatIndex + patternLength + scanRange;

         /******************** range checks ********************/
         //check that we do not search too far within an existing repeat when scanning right
         int scanRightMinBegin = lastRepeatIndex + patternLength + minSpacerLength;

         if (beginSearch < scanRightMinBegin)
            beginSearch = scanRightMinBegin;

         //System.out.print("beginSearch " + beginSearch + "  " + "endSearch" + endSearch);
         if (beginSearch > sequenceLength - 1)
            return candidateCRISPR;
         if (endSearch > sequenceLength)
            endSearch = sequenceLength;

         if ( beginSearch >= endSearch)
            return candidateCRISPR;
         /******************** end range checks ********************/

         text = DNASequence.seq.substring(beginSearch, endSearch);
         position = searchUtil.boyer_mooreSearch(text, pattern);

         if (position >= 0)
         {
            candidateCRISPR.addRepeat(beginSearch + position);
            secondToLastRepeatIndex = lastRepeatIndex;
            lastRepeatIndex = beginSearch + position;
            repeatSpacing = lastRepeatIndex - secondToLastRepeatIndex;
            if (repeatSpacing < (minSpacerLength + patternLength))
               moreToSearch = false;
         }
         else
            moreToSearch = false;
      }

      return candidateCRISPR;
   }