fixed bug in clustering function
applied clustering function in the rate calculation