Index: voting/src/main/java/geniusweb/voting/CollectedVotes.java
===================================================================
--- voting/src/main/java/geniusweb/voting/CollectedVotes.java	(revision 21)
+++ voting/src/main/java/geniusweb/voting/CollectedVotes.java	(revision 22)
@@ -4,8 +4,6 @@
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.stream.Collectors;
 
 import geniusweb.actions.PartyId;
@@ -31,8 +29,8 @@
 	 * 
 	 * @param votesMap the {@link Votes} done for each party
-	 * @param power  the power of each party. The power is an integer number. In
-	 *               the voting process, the party powers add up to form the
-	 *               total voting power. This set may contain parties that are
-	 *               not in newmap.
+	 * @param power    the power of each party. The power is an integer number.
+	 *                 In the voting process, the party powers add up to form
+	 *                 the total voting power. This set may contain parties that
+	 *                 are not in newmap.
 	 */
 	public CollectedVotes(Map<PartyId, Votes> votesMap,
@@ -132,9 +130,7 @@
 	 * @param votes a list of all votes for a particular bid. The parties that
 	 *              placed the votes are called 'voters'
-	 * @return a subset of the voters for which holds (1) the min-power
-	 *         condition of all these voters is satisfied (2) the power of this
-	 *         subset of voters is maximal (no other satisfied set of voters
-	 *         with bigger power exists) maximum-power that placed votes with
-	 *         holding conditions.This algorithm works in quadratic time.
+	 * @return a consensusgroup with maximum power, so there is no other
+	 *         consensus group that has more power (but there may be other
+	 *         groups with same power).
 	 */
 	protected Set<PartyId> getMaxPowerGroup(Set<Vote> votes) {
@@ -142,16 +138,9 @@
 		Integer maxpower = 0;
 
-		for (Vote vote : votes) {
-			int target = vote.getMinPower();
-
-			// find parties that would join if we reach that power
-			Set<PartyId> group = votes.stream()
-					.filter(v -> target >= v.getMinPower())
-					.map(v -> v.getActor()).collect(Collectors.toSet());
-			// check what the group's power is
-			Integer groupPower = getTotalPower(group);
-			if (groupPower >= target && groupPower > maxpower) {
-				maxgroup = group;
-				maxpower = groupPower;
+		for (Set<PartyId> parties : getConsensusGroups(votes)) {
+			Integer power = getTotalPower(parties);
+			if (power > maxpower) {
+				maxgroup = parties;
+				maxpower = power;
 			}
 		}
@@ -169,5 +158,5 @@
 	 *         input size.
 	 */
-	protected Set<Set<PartyId>> getConsensusGroups(List<Vote> votes) {
+	protected Set<Set<PartyId>> getConsensusGroups(Set<Vote> votes) {
 		Set<Set<PartyId>> groups = new HashSet<>();
 
@@ -177,6 +166,7 @@
 		for (ImmutableList<Vote> voteList : allVotePermutations) {
 			Set<PartyId> parties = getParties(voteList);
-			if (parties.size() >= 2
-					&& getTotalPower(parties) >= getMinPower(voteList)) {
+			Integer totalpower = getTotalPower(parties);
+			if (parties.size() >= 2 && totalpower >= getMinPower(voteList)
+					&& totalpower <= getMaxPower(voteList)) {
 				groups.add(parties);
 			}
@@ -210,4 +200,19 @@
 		}
 		return max;
+	}
+
+	/**
+	 * 
+	 * @param votes a list of {@link Vote}s on one Bid. All parties must be
+	 *              known
+	 * @return the maximum voting power needed for this group, so that all can
+	 *         accept. This is equal to the min of the vote.getMaxPower
+	 */
+	private Integer getMaxPower(ImmutableList<Vote> votes) {
+		int min = Integer.MAX_VALUE;
+		for (Vote vote : votes) {
+			min = Math.min(min, vote.getMaxPower());
+		}
+		return min;
 	}
 
Index: voting/src/test/java/geniusweb/voting/CollectedVotesTest.java
===================================================================
--- voting/src/test/java/geniusweb/voting/CollectedVotesTest.java	(revision 21)
+++ voting/src/test/java/geniusweb/voting/CollectedVotesTest.java	(revision 22)
@@ -2,4 +2,5 @@
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.mock;
 
@@ -35,13 +36,14 @@
 	private final PartyId partyQ = new PartyId("partyQ");
 	private final PartyId partyR = new PartyId("partyR");
-
-	private final Vote votePA2 = new Vote(partyP, bidA, 2);
-	private final Vote voteQA2 = new Vote(partyQ, bidA, 2);
-	private final Vote voteQB3 = new Vote(partyQ, bidB, 3);
-	private final Vote voteQB2 = new Vote(partyQ, bidB, 2);
-	private final Vote voteRA2 = new Vote(partyR, bidA, 2);
-	private final Vote voteRA3 = new Vote(partyR, bidA, 3);
-	private final Vote voteRA4 = new Vote(partyR, bidA, 4);
-	private final Vote voteRB2 = new Vote(partyR, bidB, 2);
+	private final PartyId partyS = new PartyId("partyS");
+
+	private final Vote votePA2 = new Vote(partyP, bidA, 2, 9);
+	private final Vote voteQA2 = new Vote(partyQ, bidA, 2, 9);
+	private final Vote voteQB3 = new Vote(partyQ, bidB, 3, 9);
+	private final Vote voteQB2 = new Vote(partyQ, bidB, 2, 9);
+	private final Vote voteRA2 = new Vote(partyR, bidA, 2, 9);
+	private final Vote voteRA3 = new Vote(partyR, bidA, 3, 9);
+	private final Vote voteRA4 = new Vote(partyR, bidA, 4, 9);
+	private final Vote voteRB2 = new Vote(partyR, bidB, 2, 9);
 
 	private Map<PartyId, Integer> allpowers = new HashMap<>();
@@ -73,4 +75,5 @@
 		allpowers.put(partyQ, 1);
 		allpowers.put(partyR, 1);
+		allpowers.put(partyS, 1);
 	}
 
@@ -156,6 +159,6 @@
 				allpowers);
 
-		Set<Set<PartyId>> consensus = cv
-				.getConsensusGroups(Arrays.asList(votePA2, voteQA2));
+		Set<Set<PartyId>> consensus = cv.getConsensusGroups(
+				new HashSet<>(Arrays.asList(votePA2, voteQA2)));
 		// should give 1 solution: both parties join in.
 		System.out.println(consensus);
@@ -169,6 +172,6 @@
 				allpowers);
 
-		Set<Set<PartyId>> consensus = cv
-				.getConsensusGroups(Arrays.asList(votePA2, voteQA2, voteRA4));
+		Set<Set<PartyId>> consensus = cv.getConsensusGroups(
+				new HashSet<>(Arrays.asList(votePA2, voteQA2, voteRA4)));
 		// should give 1 solution: P and Q join in. 4 is unreachable.
 		System.out.println(consensus);
@@ -182,6 +185,6 @@
 				allpowers);
 
-		Set<Set<PartyId>> consensus = cv
-				.getConsensusGroups(Arrays.asList(votePA2, voteQA2, voteRA2));
+		Set<Set<PartyId>> consensus = cv.getConsensusGroups(
+				new HashSet<>(Arrays.asList(votePA2, voteQA2, voteRA2)));
 		// should give 4 solutions: P+Q, P+R, Q+R and P+Q+R
 		System.out.println(consensus);
@@ -200,6 +203,6 @@
 				allpowers);
 
-		Set<Set<PartyId>> consensus = cv
-				.getConsensusGroups(Arrays.asList(votePA2, voteQA2, voteRA4));
+		Set<Set<PartyId>> consensus = cv.getConsensusGroups(
+				new HashSet<>(Arrays.asList(votePA2, voteQA2, voteRA4)));
 		// should give solutions P+Q and P+Q+R
 		System.out.println(consensus);
@@ -244,3 +247,54 @@
 	}
 
+	@Test
+	public void getConsensusGroupMaxPower() {
+		Vote P = new Vote(partyP, bidA, 2, 3);
+		Vote Q = new Vote(partyQ, bidA, 2, 3);
+		Vote R = new Vote(partyR, bidA, 2, 3);
+		Vote S = new Vote(partyS, bidA, 2, 3);
+		Map<PartyId, Votes> allvotes = new HashMap<>();
+		allvotes.put(partyP, new Votes(partyP, Arrays.asList(P)));
+		allvotes.put(partyQ, new Votes(partyQ, Arrays.asList(Q)));
+		allvotes.put(partyR, new Votes(partyR, Arrays.asList(R)));
+		allvotes.put(partyS, new Votes(partyS, Arrays.asList(S)));
+
+		CollectedVotes cv = new CollectedVotes(allvotes, allpowers);
+		Set<Set<PartyId>> consensus = cv.getConsensusGroups(
+				new HashSet<Vote>(Arrays.asList(P, Q, R, S)));
+		System.out.println(consensus);
+		// check that all are size 2 or 3.
+		for (Set<PartyId> set : consensus) {
+			assertTrue(set.size() == 2 || set.size() == 3);
+		}
+
+	}
+
+	@Test
+	public void getConsensusGroupMaxPowerModifiedPartyPowers() {
+		// party R gets power 2.
+		Vote P = new Vote(partyP, bidA, 2, 3);
+		Vote Q = new Vote(partyQ, bidA, 2, 3);
+		Vote R = new Vote(partyR, bidA, 2, 3);
+		Map<PartyId, Votes> allvotes = new HashMap<>();
+		allvotes.put(partyP, new Votes(partyP, Arrays.asList(P)));
+		allvotes.put(partyQ, new Votes(partyQ, Arrays.asList(Q)));
+		allvotes.put(partyR, new Votes(partyR, Arrays.asList(R)));
+
+		Map<PartyId, Integer> powers = new HashMap<PartyId, Integer>();
+		powers.put(partyP, 1);
+		powers.put(partyQ, 1);
+		powers.put(partyR, 2);
+
+		CollectedVotes cv = new CollectedVotes(allvotes, powers);
+		Set<Set<PartyId>> consensus = cv
+				.getConsensusGroups(new HashSet<Vote>(Arrays.asList(P, Q, R)));
+		System.out.println(consensus);
+		// R has power 2 now. That means groups of size 3 are not posisble.
+		// check that all are size 2.
+		for (Set<PartyId> set : consensus) {
+			assertTrue(set.size() == 2);
+		}
+
+	}
+
 }
Index: voting/src/test/java/geniusweb/voting/votingevaluators/LargestAgreementsLoopTest.java
===================================================================
--- voting/src/test/java/geniusweb/voting/votingevaluators/LargestAgreementsLoopTest.java	(revision 21)
+++ voting/src/test/java/geniusweb/voting/votingevaluators/LargestAgreementsLoopTest.java	(revision 22)
@@ -74,11 +74,12 @@
 	@Test
 	public void testCollectVotes() {
-		Votes vote1AB = new Votes(party1,
-				Arrays.asList(new Vote(party1, a, 2), new Vote(party1, b, 2)));
-		Votes vote2AB = new Votes(party2,
-				Arrays.asList(new Vote(party2, a, 2), new Vote(party2, b, 2)));
-		Votes vote3C = new Votes(party3, Arrays.asList(new Vote(party3, c, 2)));
-		Votes vote4AC = new Votes(party4,
-				Arrays.asList(new Vote(party4, a, 2), new Vote(party4, c, 2)));
+		Votes vote1AB = new Votes(party1, Arrays
+				.asList(new Vote(party1, a, 2, 9), new Vote(party1, b, 2, 9)));
+		Votes vote2AB = new Votes(party2, Arrays
+				.asList(new Vote(party2, a, 2, 9), new Vote(party2, b, 2, 9)));
+		Votes vote3C = new Votes(party3,
+				Arrays.asList(new Vote(party3, c, 2, 9)));
+		Votes vote4AC = new Votes(party4, Arrays
+				.asList(new Vote(party4, a, 2, 9), new Vote(party4, c, 2, 9)));
 		// party 1,2,4 vote for A, party 1,2 vote for B, party 3,4 vote for C.
 		// the biggest vote is P,Q,S
