clean and organize control.js code structure