restruct the controller.js file