Refactored app.js