Added histogram calculation code