refactor code added controller.js