Merge with upstream

Merge of code with upstream branch. Rolled forward fixes and
modifications into the C# version