added detection of erroneous records in function ...count_dist part II