Added some bounds checking and filling most of the previously unused histograms