refactored code for UI