refractored app.js and models