Refactored GUI code