Refactoring controller.js