refactor the way database connections are handled

closes #6