Refactoring code for connecting to a database and changing a database. #169 has been mostly tested