Simplified the logic of the parallel algorithm
Properly delete histograms after usage