Refactored UI code