A port of Arbaro to C# with enhancements