updated and refactored app.js