small performance optimisations in statistics