half rewritten to enable multiple histograms and multiple plots