moved core code to histogram.cpp