refactored app.js + firebase

improvments