Finished controller.js for front-end.