modified foreach