Fixed multiple calls to authenticate and connect to the database.