private void findNextPotentialReference(int startPosition) {
      nextPotentialReferencePosition = Math.max(startPosition, nextSemicolonPosition - MAX_REFERENCE_SIZE);

      do {
         nextPotentialReferencePosition =
               originalMessage.indexOf('&', nextPotentialReferencePosition);

         if (nextSemicolonPosition != -1 &&
               nextSemicolonPosition < nextPotentialReferencePosition)
            nextSemicolonPosition = originalMessage.indexOf(';', nextPotentialReferencePosition + 1);

         boolean isPotentialReference =
               nextPotentialReferencePosition != -1
               && nextSemicolonPosition != -1
               && nextPotentialReferencePosition - nextSemicolonPosition < MAX_REFERENCE_SIZE;

         if (isPotentialReference) {
            break;
         }
         if (nextPotentialReferencePosition == -1) {
            break;
         }
         if (nextSemicolonPosition == -1) {
            nextPotentialReferencePosition = -1;
            break;
         }

         nextPotentialReferencePosition = nextPotentialReferencePosition + 1;
      }
      while (nextPotentialReferencePosition != -1);
   }