Adapted the code to match a little better C# conventions and requirements.