Refactoring the widget ui code