Converted foreach loops to LINQ expressions a la ReSharper