Here's a solution. I believe the problem was that though you were adding an "a" in front of the key of child nodes, your add routines were referencing the parent without the "a" in front. Given this omission your nodes were probably being added to the parents indexed as 1, 2, or 3 in the nodes collection, rather than the nodes that were keyed in the collection as "a1", "a2", or "a3".
Cheers,
Mark