Refactored C# code in one single method.