refactored app.js and api.js.