don't leak the memory used for the children array when destroying a node
better error checking