Moved code from main to ctrl.