The two for loops you mentioned do different things. However, I agree the purpose of this code is hard to grasp in its current form. I am intentionally not telling you what the code does; please look at the few refactoring commits I just pushed to rt46718 and let me know if it is clear now. If it is not, even more comments are likely due.