bugfix: replaced array_walk (hack) here with a foreach to fix index generation