Refactors db connections & app dependence to work better in different environments