speed improvements to histogram clustering