Minor cleanup
Refactored 'controls_repeat' for later reuse

The part of 'controls_repeat' that generates the body of the loop has been
refactored so that it can be reused by 'controls_repeat_ext'.
Implemented 'controls_repeat_ext'