refactored app.js