Unique factorization of finite groups under direct sum?

I am told that finite groups have unique factorization under direct product. That is, call a nontrivial group "indivisible" if it is not isomorphic to a direct product of nontrivial groups. Then every finite group can be "factored" (by direct product) into a unique collection of indivisible groups.

In particular, if $G$ and $H$ are finite groups so that $G\times G\cong H\times H$, then $G\cong H$.

Can anyone provide a reference to a proof of these results? What is known in the infinite case? Thanks.

-
Recent related question: mathoverflow.net/questions/45668/… . Uniqueness of roots among finite structures with one-element substructures was proven by Lovasz, along with a cancellation theorem. For infinite structures, check some of the references. Gerhard "Ask Me About System Design" Paseman, 2010.11.19 – Gerhard Paseman Nov 19 '10 at 22:37

Update. Hirshon, found two non-isomorphic finitely generated nilpotent (infinite) groups $G,H$ such that $G\times G\cong H\times H$.
@Tim: I did not know that. What are these $G$ and $H$? I think that if $G$ is finite, then it is exactly the set of all torsion elements in ${\mathbb Z}\times G$. So $G$ must be isomorphic to $H$ if ${\mathbb Z}\times G\cong {\mathbb Z}\times H$. But perhaps I am wrong and do not see something obvious. – Mark Sapir Nov 19 '10 at 23:50
@Tim: It is proved here: springerlink.com/content/k7p548016pvq0163 . There, $G$ and $H$ are finitely generated and nilpotent. – Mark Sapir Nov 20 '10 at 1:12
@Mark: One simple example is $G=C_{11}\rtimes{\mathbb Z}$ with the generator of ${\mathbb Z}$ acting as $x\mapsto x^2$ and $H=C_{11}\rtimes{\mathbb Z}$ with the generator of ${\mathbb Z}$ acting as $x\mapsto x^7$. Then ${\mathbb Z}\times G\cong{\mathbb Z}\times H$ but $G\not\cong H$, if I am not mistaken. – Tim Dokchitser Nov 21 '10 at 1:26
@Mark: The $C_{11}$ is unique in $G$ (torsion subgroup), and the quotient $G/C_{11}\cong Z$ has two canonical elements (generators), $\pm1\in Z$. They act by $2,2^{-1}=6\in(Z/11Z)^\times$ on $C_{11}$. For $H$, the corresponding pair of numbers is different, $7,7^{-1}=8\in(Z/11Z)^\times$, so $G\not\cong H$. The important thing is that both $2$ and $7$ generate the whole of $(Z/11Z)^\times$, so the image of the action is the same subgroup. Otherwise $G\times Z\cong H\times Z$ has no chance to work... – Tim Dokchitser Nov 21 '10 at 11:24
...Now $G\times Z=C_{11}\rtimes (Z\times Z)$ with the two generators $e_1, e_2$ of $Z\times Z$ acting by conjugation as $x\mapsto x^2$ and $x\mapsto x$. Choose another basis of $Z\times Z$, say $f_1=7e_1+2e_2, f_2=10e_1+3e_2$. The determinant of this transformation is 7*3-2*10=1, so it is a basis. Then $f_1$ and $f_2$ act by $x\mapsto x^{2^7}=x^7$ and $x\mapsto x^{2^{10}}=x$, so $G\times Z\cong (C_{11}\rtimes \langle f_1\rangle)\times \langle f_2\rangle\cong H\times Z$, as promised. (To make a long story short, an extra $Z$ keeps the action image but may mess up the generators.) – Tim Dokchitser Nov 21 '10 at 11:42