Refactoring UI Code