Abstract app.js, refactor