Added database count protection