changed readNode and writeNode so that last child is added correctly