Fixed histogram/thresholding. Broke density calculation.