Refactored app.js heavily