Refactor MainWindow.