refactor ui code