Refactored sidebar code