It would probably be better to calculate the parent_section outside the loop.