 
 	def put(identity_id, power) do
 		Agent.update(__MODULE__, &Map.put(&1, identity_id, power))
+	end
+end
+
+defmodule Democracy.TotalDelegationsWeightServer do
+	def start_link do
+		Agent.start_link(fn -> {Map.new, MapSet.new} end, name: __MODULE__)
+	end
+
+	def get(identity_id) do
+		Agent.get(__MODULE__, fn({weights, done_ids}) ->
+			Map.get(weights, identity_id)
+		end)
+	end
+
+	def add(identity_id, weight) do
+		Agent.update(__MODULE__, fn({weights, done_ids}) ->
+			new_total = Map.get(weights, identity_id, 0) + weight
+			{Map.put(weights, identity_id, new_total), done_ids}
+		end)
+	end
+
+	def is_done?(identity_id) do
+		Agent.get(__MODULE__, fn({weights, done_ids}) ->
+			MapSet.member?(done_ids, identity_id)
+		end)
+	end
+
+	def add_done(identity_id) do
+		Agent.update(__MODULE__, fn({weights, done_ids}) ->
+			{weights, MapSet.put(done_ids, identity_id)}
+		end)
 	end
 end
 

		watch = Stopwatch.Watch.new

		Democracy.VotingPowerServer.start_link

		contributions = Enum.map(votes, fn({identity_id, data}) ->
			if MapSet.member?(trust_identity_ids, identity_id) do

		}
	end

	def calculate_total_weights(identity_id, inverse_delegations, votes, topics, trust_identity_ids) do
		unless Democracy.TotalDelegationsWeightServer.is_done?(identity_id) do
			inverse_delegations |> Map.get(identity_id, %{}) |> Enum.each(fn({from_identity_id, {from_weight, from_topics}}) ->
				cond do
					not MapSet.member?(trust_identity_ids, from_identity_id) -> nil
					Map.has_key?(votes, from_identity_id) -> nil
					topics != nil and from_topics != nil and MapSet.disjoint?(topics, from_topics) -> nil
					true ->
						Democracy.TotalDelegationsWeightServer.add(from_identity_id, from_weight)
						calculate_total_weights(from_identity_id, inverse_delegations, votes, topics, trust_identity_ids)
				end
			end)
			Democracy.TotalDelegationsWeightServer.add_done(identity_id)
		end
	end

	def get_power(identity_id, inverse_delegations, votes, topics, trust_identity_ids) do
		power = Democracy.VotingPowerServer.get(identity_id)
		if power do
			power
		else
			receiving = inverse_delegations |> Map.get(identity_id, %{}) |> Enum.reduce(0, fn({from_identity_id, {from_weight, from_topics}}, acc) ->
				acc + cond do
					not MapSet.member?(trust_identity_ids, from_identity_id) -> 0
					Map.has_key?(votes, from_identity_id) -> 0
					topics != nil and from_topics != nil and MapSet.disjoint?(topics, from_topics) -> 0
					true ->
						from_power = get_power(from_identity_id, inverse_delegations, votes, topics, trust_identity_ids)
						from_power * (from_weight / Democracy.TotalDelegationsWeightServer.get(from_identity_id))
				end
			end)
			power = 1 + receiving
