refactors sidebar toggle logic