Organized gui code; some refactoring and comment fixes