Refactoring the control plane code