Code refactoring and make MainWindow dispose on close not exit app