dist_hist.r workable version