Refactored app.js and server.js to be more DRY