Restructure control logic