Moved main window GUI into a function