streamlined calculate histogram
added verbose phpdoc comments