restructured app.js