Refactoring C# code