app.js refactored