Added database errors check