refactoring a plotHistograms