Cleaned up and documented the C# and Java versions