Refactor histogram