fix bucketing algorithm