Updated to use arrays rather than histograms