public static int calcTopOfRange(double topPct, int topIdx, int botIdx, double[][] strats, double[] freqs, int nutsRank, TreeMap<HandRank, TreeSet<PairRank>> pairRankSets) {
		int thresh = 0;
		double totTopFreqs = 0;
		double rankTotTopFreqs = 0;
		double partialFreq = 0;
		
		totTopFreqs = getDoubleArrayTotal(freqs);
		
		double remTopFreq = topPct * totTopFreqs;
		
		for (HandRank key : pairRankSets.keySet()) {
			rankTotTopFreqs = getTotalRankFreq(freqs, pairRankSets.get(key));
			
			if (rankTotTopFreqs > 0) {			
				if (key.getRank() == nutsRank) {
					thresh = nutsRank;
					for (PairRank pairRank: pairRankSets.get(key)) {
						if (pairRank.getRank() == nutsRank) {
							strats[pairRank.getOrdinal()][botIdx] = 0;
							strats[pairRank.getOrdinal()][topIdx] = 1;
							remTopFreq -= freqs[pairRank.getOrdinal()];
						}
					}
				} else {
					if (remTopFreq > rankTotTopFreqs) {
						thresh = key.getRank();
						partialFreq = 1;
					} else if (remTopFreq <= 0) {
						partialFreq = 0;
					} else {
						thresh = key.getRank();
						partialFreq = remTopFreq/rankTotTopFreqs;
						remTopFreq = -1;
					}
					
					for (PairRank pairRank: pairRankSets.get(key)) {
						if (freqs[pairRank.getOrdinal()] > 0) {
							strats[pairRank.getOrdinal()][botIdx] = 1 - partialFreq;
							strats[pairRank.getOrdinal()][topIdx] = partialFreq;
							remTopFreq -= (partialFreq * freqs[pairRank.getOrdinal()]);
						}
					}
				}
			}
		}
		
		return thresh;
	}