Upgrading foreach