refactored a lot of the histogram pyramids code