I'm having trouble understanding a function, in relation to binary rooted trees

Def'n: abinaryrootedtree is a tree with a root node in which every node has at most two children.Let $\displaystyle T(x,y)=\sum_{T\in{B}} x^{n(T)}y^{z(T)}$

Def'n: A terminal is a node with no children

Let T be a tree, B the set of all BRTs, n(T) counts the number of nodes in T, z(T) counts the number of terminals

Noting the recursive structure of BRTs, let L be the left subtree, R the right subtree

$\displaystyle z(T)= z(L)+z(R)$ if either L or R not empty, 1 if both are empty

$\displaystyle n(T)= 1+ n(L)+n(R)$

Thus (this step I don't understand)

$\displaystyle T(x,y)=\sum_{T\in{B}} x^{n(T)}y^{z(T)}$

$\displaystyle =xy+\sum_{L\in{B}} x^{n(L)}y^{z(L)}+\sum_{R\in{B}} x^{n(R)}y^{z(R)}+\sum_{(L,R)\in{BxB}} x^{n(L)+n(R)}y^{z(L)+z(R)}$

$\displaystyle =x(y+2T(x,y)+[T(x,y)]^2)$

I'm having trouble understanding how the function is broken down.

Help please?