refactoring app.js file