Major GUI code refactoring