histogram storage and refactoring