If we traverse in normal order, there are no rows available after the first iteration as the first row=root gets collapsed. Extracting rowCount variable before the loop takes place does not help either. I can think of changing it to "make sure all sub-expansions get collapsed" - if you can think of something shorter and more explanatory, I'm open to suggestions :-)