Added the pack_elements range accessor. Refactoring some for loops to use range-based for loops instead. No functional changes intended.