Implement pane toggling with some refactoring.