refactor the ui code