refactored code in app.js