Refactored control loops by merging together