Code structure

Moving stuff out of MainWindow and basic cleanup