refactoring of controller.js