safe foreach