Refactored app.js

did some refactoring of app.js, there is still more that could be done
to clean it up.