scan bodged together, works for histograms with minimum of 1024 bins
further changes to max scan