Refactored UI Code