Some UI code refactoring