Refactored some GUI code in MainGui.