Reorganize C# code