refactoring ui code