tidied code, improved histo