Multiple fixes for histogram generation