extract method and memoize histogram