refactor main js code to app.js