Removing foreach where it affects shortcircuiting