major refactor for mainwindow