Update app.js

Refactor code to fit MVC format