refactor sidebar code