Move control code to the controller instead of a lonely library