refactor controller js file