refactor widget code