Tweaked to work with .NET Framework 4.0