Refactor control panel context

This depends on #990 and #991.

This should allow #994 through a cleaner code interface.

Nothing should change, just refactoring & cleaning up code.