      //
      // A bitvector indexed by offset in the read indicating whether this seed is used.
      // This is here to avoid doing a memory allocation in the aligner.
-@@ -257,6 +260,7 @@ private:
+@@ -257,6 +260,8 @@ private:
      unsigned lvScoresAfterBestFound;
      double probabilityOfAllCandidates;
      double probabilityOfBestCandidate;
++	_int64 minHashTableHits[NUM_DIRECTIONS];
 +    double probabilityOfSecondBestCandidate;
      int firstPassSeedsNotSkipped[NUM_DIRECTIONS];
      _int64 smallestSkippedSeed[NUM_DIRECTIONS];

         qnameLen, read->getId(),
         flags,
         contigName,
@@ -1263,7 +1303,8 @@ SAMFormat::writeRead(
         fullLength, quality,
         aux != NULL ? "\t" : "", auxLen, aux != NULL ? aux : "",
         readGroupSeparator, readGroupString,

     unsigned scoreLimit = maxK + extraSearchDepth;
 
     //
@@ -350,6 +352,7 @@ IntersectingPairedEndAligner::align(
                 } else {
                     offset = readLen[whichRead] - seedLen - nextSeedToTest;
                 }
+				minHashTableHits[whichRead][dir] = min(minHashTableHits[whichRead][dir], nHits[dir]);
                 if (nHits[dir] < maxBigHits) {
                     totalHashTableHits[whichRead][dir] += nHits[dir];
                     if (doesGenomeIndexHave64BitLocations) {
@@ -756,6 +759,7 @@ IntersectingPairedEndAligner::align(
                                     (*nSecondaryResults)++;
 
                                 }
+								secondBestPairScore = bestPairScore;
                                 bestPairScore = pairScore;
                                 probabilityOfBestPair = pairProbability;
                                 bestResultGenomeLocation[readWithFewerHits] = candidate->readWithFewerHitsGenomeLocation + fewerEndGenomeLocationOffset;
@@ -771,6 +775,9 @@ IntersectingPairedEndAligner::align(
 
                                 isBestHit = true;
                             } else {
+								if(pairScore > secondBestPairScore) {
+									secondBestPairScore = pairScore;
+								}
                                 if (maxEditDistanceForSecondaryResults != -1 && (unsigned)maxEditDistanceForSecondaryResults >= pairScore - bestPairScore) {
                                     //
                                     // A secondary result to save.
@@ -852,9 +859,28 @@ doneScoring:
 #endif  // DEBUG
         }
     } else {
