widget code refactored