histogram() was rewritten for better performance.