Content-Transfer-Encoding: binary X-Mailer: MIME-tools 5.508 (Entity 5.508) X-RT-Original-Encoding: utf-8 MIME-Version: 1.0 Content-Disposition: inline References: Content-Type: text/plain; charset="utf-8" Message-ID: X-RT-Interface: Web In-Reply-To: Content-Length: 344 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.