reformat and refactor app.js