little refactoring in mainwindow; remove leaks