De-duplicate histogram code