Cleanup of MainWindow code and addition of some useful comments