refactor sidebar widget code