refactored the ui code.