refactored ui code.