Move some code from MainWindow to Application class