refactored with comments on app.js