histogram refactoring