refactoring ui code.