Demand derived from Cobb-Douglas utility, interpretation, check I derived demand, given a Cobb-Douglas utility function but I am not really sure if I did it correctly. I am especially struggling with the sum signs and the subscripts of $i$ &amp; $j$. It would be really great if someone could check. I want to maximize utility for 2 goods, here $j$ and $i$. 

$\ u(x_i)=\prod_{i=1}^n x^a_i       $

$\ s.t.:M=\sum_{j=1}^n p_jx_j      $

$\ L= \sum_{i=1}^n a_ilogx_i+\lambda(M-\sum_{j=1}^np_jx_j) $

$ (1)\frac{\partial L}{\partial x_i} = \frac{a_i}{ x_i}-\lambda p_i=0$

$ (2)\frac{\partial L}{\partial x_j} = \frac{a_j}{ x_j}-\lambda p_j=0$

$ (3)\frac{\partial L}{\partial \lambda} = M-\sum_{j=1}^np_jx_j=0$

from (1) and (2) it follows:

$ \frac{p_i}{x_i} = \frac{a_i/x_i}{a_j/x_j}=\frac{a_ix_j}{a_jx_i}$

$ x_j = \frac{p_ja_jx_i}{p_ja_j}$

$ x_j$ into (3)

$ M = \sum_{j=1}^np_j(\frac{p_ja_jx_i}{p_j/a_j})=0$

$ x_i=  \frac{a_iM}{\sum_{j=1}^na_jp_j}$

Furthermore I would like to interpret what happens if we have an efficency shock for good $i$. Meaning, good $i$ becomes cheaper. This leads to an increase in relative income. So $M$ increases which leads to an increased demand for good $x_i$, rest hold constant. Is that correct?
From (1) and (2) you get 
$$\frac{x_j}{x_i}=\frac{a_j p_i}{a_i p_j},$$
or equivalently,
$$x_j =\frac{a_j p_i}{a_i p_j} x_i.$$
Substituting this into equation 3 for $j=2,...,n$ and $i=1$ (solving for the demand function for good 1) we get
$$M=p_1x_1 + \sum_{j=2}^n p_j  \frac{a_j p_1}{a_1 p_j} x_1$$
$$M=p_1x_1 + \sum_{j=2}^n  \frac{a_j p_1}{a_1} x_1$$
$$M=p_1x_1 + \frac{p_1}{a_1} x_1\sum_{j=2}^n a_j $$
$$M=p_1x_1(1 + \frac{1}{a_1}\sum_{j=2}^n a_j). $$
Finally, solving for $x_1$ we get
$$x_1^* = \frac{M}{p_1}(1+ \frac{\sum_{j=2}^n a_j}{a_1})^{-1}$$
$$x_1^* =\frac{a_1}{\sum_{j=1}^n a_j} \frac{M}{p_1}.$$

Analogously, 
$$x_i^*=\frac{a_i}{\sum_{j=1}^n a_j} \frac{M}{p_i},$$
for $i=1,...,n$.

As is always the case for demand functions derived from a Cobb-Douglas utility function, the consumer spends a constant share of income on each good. To see this, rearrange the previous equation to get
$$p_ix_i^*=\frac{a_i}{\sum_{j=1}^n a_j} M,$$
for $i=1,...,n$.