Upgraded code to C# .NET 4.0