refactored js code to app.js