moved to C sharp
fully translated to C#