Refactor to make connecting to the database
controlled by the config settings.