some refactoring to make app.js clear