Bug fixes in the histogram generation