Update app.js

Some improvements in the code.