Add a controller for the control panel and do some refactoring