Added territory count algorithm.