control.js: rearrange code, no functional changes