fixed error check for db