fixed calculation of histogram