Fix foreach not incrementing pointer