Fixed lifecycle issues in the control script