Moved logic from view to a widget.