Simplified the calculation code slightly

Added an assert to ensure we catch all points, removed debug/left
over code and simplified the templated function slightly.
Use a background thread to calculate histograms