rewritten app.js