Window.cs code refactoring