Moving logic to app.js