slightly adjusted to C# :^)