public synchronized int getRarestPieceToRequest(int peer) {
		int sum;

		for (int i = 0; i<numberOfPieces; i++){
			sum = 0;
			for (int j = 0; j < MAX_CONNECTIONS; j++) {
				if (j == peer) {
					bitfieldMatrix[i][peer] = bitfieldMatrix[i][peer]*50;
				}
				sum = sum + bitfieldMatrix[i][j];
			}
			bitfieldMatrix[i][MAX_CONNECTIONS-1] = sum;
		}

		int smallest = Integer.MAX_VALUE;
		int currNumber;
		int smallest_index = -1;
		for (int i=0; i<numberOfPieces;i++) {
			bitfieldMatrix[i][peer] = bitfieldMatrix[i][peer]/50;
			currNumber = bitfieldMatrix[i][MAX_CONNECTIONS-1];
			if (currNumber >= 50) {
				if (smallest > currNumber) {
					smallest = currNumber;
				}
			}
			//bitfieldMatrix[i][MAX_CONNECTIONS-1] = 0;
		}

		if (smallest == Integer.MAX_VALUE) {
			return -1;
		}

		ArrayList<Integer> list = new ArrayList<Integer>();
		Random randomPicker = new Random();
		for (int i=0;i<numberOfPieces;i++) {
			currNumber = bitfieldMatrix[i][MAX_CONNECTIONS-1];
			if (currNumber == smallest) {
				list.add(i);
			}
			bitfieldMatrix[i][MAX_CONNECTIONS-1] = 0;
		}

		int random = randomPicker.nextInt(list.size());
		smallest_index = list.get(random);
		return smallest_index;
	}