histogram and optimisations