Working code! At least the code doesn't break now when I try to normalise the histograms...