Refactoring GUI code