Moving inline JS to app.js document.on(ready)

- more tuning for #497